git.ucc.asn.au
/
uccvend-vendserver.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
more restructuring
[uccvend-vendserver.git]
/
sql-edition
/
servers
/
VendServer.py
diff --git
a/sql-edition/servers/VendServer.py
b/sql-edition/servers/VendServer.py
index
438ca06
..
9ee8ef1
100755
(executable)
--- a/
sql-edition/servers/VendServer.py
+++ b/
sql-edition/servers/VendServer.py
@@
-5,6
+5,7
@@
USE_DB = 0
import ConfigParser
import sys, os, string, re, pwd, signal
import ConfigParser
import sys, os, string, re, pwd, signal
+import logging
from traceback import print_tb
if USE_DB: import pg
from time import time, sleep
from traceback import print_tb
if USE_DB: import pg
from time import time, sleep
@@
-430,10
+431,30
@@
class VendConfigFile:
print "Error reading config file "+config_file+": " + str(e)
sys.exit(1)
print "Error reading config file "+config_file+": " + str(e)
sys.exit(1)
-def do_vend_server():
+def set_stuff_up()
+ def do_nothing(signum, stack): pass
+ def stop_server(signum, stack): raise KeyboardInterrupt
+ signal.signal(signal.SIGHUP, do_nothing)
+ signal.signal(signal.SIGTERM, stop_server)
+ signal.signal(signal.SIGINT, stop_server)
+
options = parse_args()
config_opts = VendConfigFile(options.config_file, config_options)
options = parse_args()
config_opts = VendConfigFile(options.config_file, config_options)
+ set_up_logging(options)
+ if options.daemon: become_daemon()
+
+ return options, config_opts
+def become_daemon(options):
+ dev_null = file('/dev/null')
+ fd = dev_null.fileno()
+ os.dup2(fd, 0)
+ os.dup2(fd, 1)
+ os.dup2(fd, 2)
+ if os.fork() != 0:
+ sys.exit(0)
+
+def do_vend_server(options, config_opts):
while True:
try:
rfh, wfh = connect_to_vend(options, config_opts)
while True:
try:
rfh, wfh = connect_to_vend(options, config_opts)
@@
-452,17
+473,15
@@
def do_vend_server():
print "Connection died, trying again..."
if __name__ == '__main__':
print "Connection died, trying again..."
if __name__ == '__main__':
- def do_nothing(signum, stack): pass
- def stop_server(signum, stack): raise KeyboardInterrupt
- signal.signal(signal.SIGHUP, do_nothing)
- signal.signal(signal.SIGTERM, stop_server)
- signal.signal(signal.SIGINT, stop_server)
+ options, config_opts = set_stuff_up()
while True:
try:
while True:
try:
- do_vend_server()
+ do_vend_server(
options, config_opts
)
except KeyboardInterrupt:
print "Killed by signal."
break
except KeyboardInterrupt:
print "Killed by signal."
break
+ except SystemExit, e:
+ raise e
except:
(exc_type, exc_value, exc_traceback) = sys.exc_info()
print
except:
(exc_type, exc_value, exc_traceback) = sys.exc_info()
print
@@
-474,6
+493,7
@@
if __name__ == '__main__':
print
print "This message should be considered a bug in the Vend Server."
print "Please report this to someone who can fix it."
print
print "This message should be considered a bug in the Vend Server."
print "Please report this to someone who can fix it."
+ sleep(10)
print
print "Trying again anyway (might not help, but hey...)"
print
print "Trying again anyway (might not help, but hey...)"
UCC
git Repository :: git.ucc.asn.au