[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[minion-cvs] Support daemonization more correctly



Update of /home/minion/cvsroot/src/minion/lib/mixminion/server
In directory moria.mit.edu:/tmp/cvs-serv3598/lib/mixminion/server

Modified Files:
	ServerMain.py 
Log Message:
Support daemonization more correctly

Index: ServerMain.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/server/ServerMain.py,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- ServerMain.py	21 Dec 2002 01:54:23 -0000	1.10
+++ ServerMain.py	29 Dec 2002 20:29:21 -0000	1.11
@@ -370,6 +370,21 @@
             pass
 
 #----------------------------------------------------------------------
+def daemonize():
+    """Put the server into daemon mode with the standard trickery."""
+    # ??? This 'daemonize' logic should go in Common.
+    pid = os.fork()
+    if pid != 0:
+	os._exit(0)
+    if hasattr(os, 'setsid'):
+	# Setsid is not available everywhere.
+	os.setsid()
+    sys.stderr.close()
+    sys.stdout.close()
+    sys.stdin.close()
+    sys.stdout = LogStream("STDOUT", "WARN")
+    sys.stderr = LogStream("STDERR", "WARN")
+
 def usageAndExit(cmd):
     executable = sys.argv[0]
     print >>sys.stderr, "Usage: %s %s [-h] [-f configfile]" % (executable, cmd)
@@ -419,15 +434,7 @@
 
     if not config['Server'].get("NoDaemon",0):
         print >>sys.stderr, "Starting server in the background"
-        # ??? This 'daemonize' logic should go in Common.
-        pid = os.fork()
-        if pid != 0:
-            os._exit(0)
-        sys.stderr.close()
-        sys.stdout.close()
-        sys.stdin.close()
-        sys.stdout = LogStream("STDOUT", "WARN")
-        sys.stderr = LogStream("STDERR", "WARN")
+	daemonize()
 
     LOG.info("Starting server")
     try: