summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: d0144b0)
raw | patch | inline | side by side (parent: d0144b0)
author | richard <richard@57a73879-2fb5-44c3-a270-3262357dd7e2> | |
Sat, 7 Sep 2002 22:46:19 +0000 (22:46 +0000) | ||
committer | richard <richard@57a73879-2fb5-44c3-a270-3262357dd7e2> | |
Sat, 7 Sep 2002 22:46:19 +0000 (22:46 +0000) |
git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/trunk@1091 57a73879-2fb5-44c3-a270-3262357dd7e2
roundup/scripts/roundup_server.py | patch | blob | history |
index 9179a6ecbd873b68739b64e51c8db319806afb8b..14575fab08cf310aaab1c117eaabbbf2143e1416 100644 (file)
#
""" HTTP Server that serves roundup.
-$Id: roundup_server.py,v 1.7 2002-09-04 07:32:55 richard Exp $
+$Id: roundup_server.py,v 1.8 2002-09-07 22:46:19 richard Exp $
"""
# python version check
@@ -185,6 +185,41 @@ roundup-server [-n hostname] [-p port] [-l file] [-d file] [name=instance home]*
''')%locals()
sys.exit(0)
+def daemonize(pidfile):
+ ''' Turn this process into a daemon.
+ - make sure the sys.std(in|out|err) are completely cut off
+ - make our parent PID 1
+
+ Write our new PID to the pidfile.
+
+ From A.M. Kuuchling (possibly originally Greg Ward) with
+ modification from Oren Tirosh, and finally a small mod from me.
+ '''
+ # Fork once
+ if os.fork() != 0:
+ os._exit(0)
+
+ # Create new session
+ os.setsid()
+
+ # Second fork to force PPID=1
+ pid = os.fork()
+ if pid:
+ pidfile = open(pidfile, 'w')
+ pidfile.write(str(pid))
+ pidfile.close()
+ os._exit(0)
+
+ os.chdir("/")
+ os.umask(0)
+
+ # close off sys.std(in|out|err), redirect to devnull so the file
+ # descriptors can't be used again
+ devnull = os.open('/dev/null', 0)
+ os.dup2(devnull, 0)
+ os.dup2(devnull, 1)
+ os.dup2(devnull, 2)
+
def run():
hostname = ''
port = 8080
# fork?
if pidfile:
- pid = os.fork()
- if pid:
- print 'forking', pid
- open(pidfile, 'w').write(str(pid))
- return
+ daemonize(pidfile)
- # redirect stdout/stderr
+ # redirect stdout/stderr to our logfile
if logfile:
sys.stdout = sys.stderr = open(logfile, 'a')
#
# $Log: not supported by cvs2svn $
+# Revision 1.7 2002/09/04 07:32:55 richard
+# add daemonification
+#
# Revision 1.6 2002/08/30 08:33:28 richard
# new CGI frontend support
#