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
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)
+ set_up_logging(options)
+ if options.daemon: become_daemon()
- if options.daemon:
- 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)
+ 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)
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:
- do_vend_server()
+ do_vend_server(options, config_opts)
except KeyboardInterrupt:
print "Killed by signal."
break