-
Notifications
You must be signed in to change notification settings - Fork 1
/
mabsCommandServerCGI.py
60 lines (43 loc) · 1.56 KB
/
mabsCommandServerCGI.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/python2.2
import socket,popen2,time
#
# $Log$
# Revision 1.2 2004/02/20 10:57:26 kpalin
# For use in apache web server so that the distribution
# can go through firewalls.
#
# Revision 1.1 2004/02/20 09:24:34 kpalin
# Version that sort of takes care of the file serving by it self.
# Doesn't really work.
#
#
try:
from SimpleXMLRPCServer import CGIXMLRPCRequestHandler
except ImportError:
from SimpleXMLRPCServer233 import CGIXMLRPCRequestHandler
hostname=socket.gethostname()
portno=8001
errstrm=open("mabsCom.err","a")
try:
import socket,popen2,os
from xmlrpclib import ServerProxy
servName=socket.gethostname()
(servPort,servPid,servComm)=eval(open("mabsCommandServer.portno").read())
server=ServerProxy("http://%s:%d/"%(servName,servPort))
def nextFasta(clientID):
try:
filen=server.nextFasta(clientID)
print >> errstrm, "Serving",filen,"to",os.environ["REMOTE_HOST"],"(",clientID,") at", time.asctime()
errstrm.flush()
return filen
except Exception,e:
print >> errstrm,e
if e[0]==111 and os.system("/bin/ps -no-headers %d >/dev/null"%(servPid)) != 0:
print >> errstrm, "Looks like server has died. Trying to start it."
os.system("python2.2 %s 2>/dev/null >/dev/null </dev/null &"%(servComm))
return "xTryAgain"
handler = CGIXMLRPCRequestHandler()
handler.register_function(nextFasta)
handler.handle_request()
except Exception,e:
print >> errstrm,e