[Web-SIG] Daemon server management

Ian Bicking ianb at colorstudy.com
Thu Jun 9 20:52:52 CEST 2005

Jacob Smullyan wrote:
> On Thu, Jun 09, 2005 at 01:26:17PM -0500, Ian Bicking wrote:
>>Does anyone have opinions on how to start and stop daemon servers?  I've
>>added a --daemon option to paster serve, but I'd like to implement stop,
>>restart, and reload as well.  Whenever I encounter servers that clobber
>>pid files, or where the only way you can tell you've started a server
>>twice is that you get an error message about not being able to bind to
>>the port, it annoys me.  But I'm not sure how to best implement a better
>>system.  Especially cross-platform -- though an entirely separate
>>process for Windows might make sense (as a windows service or something).
>>Opinions?  Or examples of other servers (preferably Python-based) that
>>do this well?
> Clobbering pid files is a no-no; but getting an error about a port
> being already in use doesn't seem terrible to me. 

Yes, but how to avoid clobbering pid files?  It's probably a beginner 
question, and I've found workable things in the os module, but I don't 
actually know the right way to do this.

> What would you
> rather it say when two different server installations on the same
> system try to open the same port?  Should the server configuration
> really need to know that it is or is not the "same instance" of the
> server as the one owning the port?  A program being stupid in the
> right way is a feature.  In fact, a user getting annoyed by an error
> message in the right way is a feature, too, especially when the user
> has made a mistake!

I'd agree it's wrong to be clever and notice that the process is already 
running, then exiting without error.  But it's right to notice the other 
process is running, and exit with a helpful error; helpful errors are 
always right.  Should I even try to connect to a port if the process in 
the pid file is still alive, or should I bail immediately?

> I'd advocate the standard UNIX behavior for UNIX machines; pid file,
> conventional signal handling (in particular, HUP reloads).  For
> Windows, the standard Windows behavior, whatever that might be; a
> cross-platform solution would be neither fish nor fowl.  This is not
> just a matter of taste; conforming to the platform's expectations in
> this area is the gracious thing to do, since packagers and system
> administrators do not relish constantly having to write special
> wrappers for non-standard daemons.

I'm happy to copy conventions.  Does anyone recommend a particular 
document on those conventions?  For things like, do I open log files 
before or after I change user id (assuming the server is started as 
root)?  And I'm a complete blank slate when it comes to the Windows 
side.  Or even Macs, though I'm okay treating them like Unix to start.

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

More information about the Web-SIG mailing list