[Web-SIG] Daemon server management
ianb at colorstudy.com
Sat Jun 11 00:28:49 CEST 2005
As a followup on this, this is what I have so far:
f = open(pidfile)
pid = int(f.read().strip())
os.kill(pid, signal.SIG_DFL) # SIG 0, should do nothing
# 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:
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