1 |
|
import os, sys |
2 |
+ |
import coral |
3 |
|
import cherrypy |
4 |
|
from optparse import OptionParser |
5 |
+ |
import DLFCN |
6 |
+ |
sys.setdlopenflags(DLFCN.RTLD_GLOBAL+DLFCN.RTLD_LAZY) |
7 |
+ |
from Applications import iovInspect, iovExport, globaltag,serviceMap |
8 |
+ |
from Common import config |
9 |
+ |
from pluginCondDBPyInterface import * |
10 |
+ |
|
11 |
|
class Root(object): |
12 |
|
@cherrypy.expose |
13 |
|
def index(self): |
17 |
|
|
18 |
|
class Server(object): |
19 |
|
def __init__(self): |
20 |
< |
"""Constructor |
21 |
< |
""" |
22 |
< |
self.__parser=OptionParser() |
23 |
< |
self.__parser.add_option("--basedir",action="store",dest="basedir", |
17 |
< |
help="application base installation dir default $HOME") |
18 |
< |
self.__parser.add_option("--hostname",action="store",dest="hostname", |
19 |
< |
help="hostname default localhost") |
20 |
< |
self.__parser.add_option("-p","--port",action="store",dest="port", |
21 |
< |
help="port default 8086") |
22 |
< |
self.__parser.add_option("","--cmsswversion",action="store", |
23 |
< |
dest="cmsswversion", help="cmsswversion(required)") |
24 |
< |
self.__platform='slc4_ia32_gcc345' |
25 |
< |
|
26 |
< |
def __setuprunenv(self,basedir,cmsswversion): |
27 |
< |
"""Set up cmssw running environment according to installation location and cmssw version |
28 |
< |
""" |
29 |
< |
cmsswlocation=os.path.join(basedir,self.__platform,'cms','cmssw',cmsswversion) |
30 |
< |
currentdir=os.path.dirname(os.path.abspath(__file__)) |
31 |
< |
print 'cmsswlocation',cmsswlocation |
32 |
< |
os.chdir(cmsswlocation) |
33 |
< |
stdout_handle = os.popen('scramv1 runtime -sh', 'r') |
34 |
< |
text=stdout_handle.read() |
35 |
< |
new_string = '' |
36 |
< |
for line in text.split('\n'): |
37 |
< |
if line.strip(): |
38 |
< |
new_string += line |
39 |
< |
new_string=new_string.replace('export ',' ').strip(';') |
40 |
< |
new_string=new_string.replace('; ',' ').strip(' ') |
41 |
< |
for env in new_string.split('" '): |
42 |
< |
(k,v)=env.split('="') |
43 |
< |
if k in ['PATH','LD_LIBRARY_PATH','TNS_ADMIN','ORACLE_HOME','ORA_NLS33','SEAL_PLUGINS','ROOTSYS','PYTHONPATH'] : |
44 |
< |
if os.environ.has_key(k): |
45 |
< |
os.environ[k]+=':'+v |
46 |
< |
else: |
47 |
< |
os.environ[k]=v |
48 |
< |
if k=='PYTHONPATH': |
49 |
< |
print os.environ[k] |
50 |
< |
os.chdir(currentdir) |
20 |
> |
self.__hostname='localhost' |
21 |
> |
self.__port=6789 |
22 |
> |
self.__appconfigfile='application.conf' |
23 |
> |
self.__detconfigfile='detector.conf' |
24 |
|
def start (self): |
25 |
|
"""Start server |
26 |
|
""" |
27 |
< |
(options, args) = self.__parser.parse_args() |
28 |
< |
basedir=os.environ['HOME'] |
29 |
< |
if options.basedir: |
30 |
< |
basedir=options.basedir |
31 |
< |
hostname='localhost' |
27 |
> |
parser=OptionParser() |
28 |
> |
parser.add_option("--port",action="store",dest="port", |
29 |
> |
help="port default 6789") |
30 |
> |
parser.add_option("--hostname",action="store",dest="hostname", |
31 |
> |
help="hostname default localhost") |
32 |
> |
parser.add_option("--configdir",action="store",dest="configdir", |
33 |
> |
help="configuration dir. Default to currentdir/config") |
34 |
> |
(options, args) = parser.parse_args() |
35 |
|
if options.hostname: |
36 |
< |
hostname=options.hostname |
61 |
< |
port=8086 |
36 |
> |
self.__hostname=options.hostname.strip(' ') |
37 |
|
if options.port: |
38 |
< |
port=int(options.port) |
39 |
< |
cmsswversion=options.cmsswversion.strip(' ') |
40 |
< |
self.__setuprunenv(basedir,cmsswversion) |
41 |
< |
|
42 |
< |
from Applications import iov,globaltag,serviceMap |
43 |
< |
serverconfig={'global':{'server.socket_host':hostname,'server.socket_port':port,'server.environment':'production'}} |
38 |
> |
self.__port=int(options.port) |
39 |
> |
if options.configdir: |
40 |
> |
self.__configdir = options.configdir.strip(' ') |
41 |
> |
else: |
42 |
> |
currentdir=os.path.dirname(os.path.abspath(__file__)) |
43 |
> |
self.__configdir = os.path.join(currentdir,'config') |
44 |
> |
serverconfig={'global':{'server.socket_host':self.__hostname,'server.socket_port':self.__port,'server.environment':'production'}} |
45 |
|
cherrypy.config.update(serverconfig) |
46 |
|
cherrypy.tree.mount(Root(),script_name='/') |
47 |
< |
currentdir=os.path.dirname(os.path.abspath(__file__)) |
48 |
< |
appconfigfile=os.path.join(currentdir,'config','application.conf') |
49 |
< |
#print 'appconfigfile',appconfigfile |
50 |
< |
cherrypy.tree.mount(iov.IOV(appconfigfile),script_name='/iov') |
51 |
< |
detconfigfile=os.path.join(currentdir,'config','detector.conf') |
52 |
< |
#print 'detconfigfile',detconfigfile |
53 |
< |
cherrypy.tree.mount(serviceMap.serviceMap(detconfigfile),script_name='/serviceMap') |
54 |
< |
cherrypy.tree.mount(globaltag.GlobalTag(appconfigfile),script_name='/globaltag') |
47 |
> |
|
48 |
> |
# here for the time being |
49 |
> |
self.__config=config.Config() |
50 |
> |
self.__config.from_ini(os.path.join(self.__configdir,self.__appconfigfile)) |
51 |
> |
self.__authpath=self.__config.common.auth_path |
52 |
> |
#os.environ["CORAL_AUTH_PATH"] = self.__authpath |
53 |
> |
#print "auth path ", os.environ["CORAL_AUTH_PATH"] |
54 |
> |
# this one shall be alive all the time... |
55 |
> |
#self.__cmsframe = FWIncantation |
56 |
> |
cherrypy.tree.mount(iovInspect.IOV(os.path.join(self.__configdir,self.__appconfigfile)),script_name='/iov') |
57 |
> |
cherrypy.tree.mount(iovExport.IOV(os.path.join(self.__configdir,self.__appconfigfile)),script_name='/exportIov') |
58 |
> |
cherrypy.tree.mount(serviceMap.serviceMap(os.path.join(self.__configdir,self.__detconfigfile)),script_name='/serviceMap') |
59 |
> |
cherrypy.tree.mount(globaltag.GlobalTag(os.path.join(self.__configdir,self.__appconfigfile)),script_name='/globaltag') |
60 |
|
cherrypy.server.quickstart() |
61 |
|
cherrypy.engine.start() |
62 |
< |
|
62 |
> |
|
63 |
|
if __name__ == '__main__': |
64 |
+ |
fileHandle=open('pid.txt','w') |
65 |
+ |
fileHandle.seek(0) |
66 |
+ |
mypid=os.getpid() |
67 |
+ |
fileHandle.write( str(mypid) ) |
68 |
+ |
fileHandle.close() |
69 |
|
s=Server() |
70 |
|
s.start() |
85 |
– |
|
71 |
|
|