[Web-SIG] Daemon server management

Ian Bicking ianb at colorstudy.com
Sat Jun 11 00:28:49 CEST 2005

As a followup on this, this is what I have so far:

When starting:

if os.path.exists(pidfile):
     f = open(pidfile)
     pid = int(f.read().strip())
         os.kill(pid, signal.SIG_DFL) # SIG 0, should do nothing
     except OSError:
         # Means no such process exists
         log('PID file %s exists, but process %i no longer running'
             % (pidfile, pid))
         print "Can't start, another server running (%i)" % pid

I guess there's some possible race conditions at this point.  But I'm 
not sure how to resolve those.  I guess I could do Jacob's 
fd=os.open(fname, os.O_CREATE | os.O_EXCL) later.  And match instead of 
os.path.exists() and open() I should open the pid file similarly in that 
code block above.

Later, when killing the process, I'm doing:

os.kill(pid, signal.SIGTERM)

But I'm not sure if that's right either.  The process seems to die, 
instead of properly terminating.  Should I send another signal, and set 
up a signal handler in the server?  Then perhaps I would send that 
signal, wait a bit, and send SIGTERM if it didn't stop on its own?

Ian Bicking  /  ianb at colorstudy.com  /  http://blog.ianbicking.org

More information about the Web-SIG mailing list