add daemonising code
[zanchey/dispense2.git] / sql-edition / servers / VendServer.py
index 438ca06..3c3aee6 100755 (executable)
@@ -434,6 +434,15 @@ def do_vend_server():
        options = parse_args()
        config_opts = VendConfigFile(options.config_file, config_options)
 
+       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)
+
        while True:
                try:
                        rfh, wfh = connect_to_vend(options, config_opts)
@@ -463,6 +472,8 @@ if __name__ == '__main__':
                except KeyboardInterrupt:
                        print "Killed by signal."
                        break
+               except SystemExit, e:
+                       raise e
                except:
                        (exc_type, exc_value, exc_traceback) = sys.exc_info()
                        print
@@ -474,6 +485,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."
+                       sleep(10)
                        print
                        print "Trying again anyway (might not help, but hey...)"
 

UCC git Repository :: git.ucc.asn.au