[Python-au] running a socket server as deamon

Richard Jones richardjones at optushome.com.au
Fri Feb 12 10:27:24 UTC 2010

On Fri, Feb 12, 2010 at 6:53 PM, jack andrews <effbiae at gmail.com> wrote:
> hi james,
>> The couple of ideas I have are:
>> * Running the socket server as a deamon.

This is easy enough to do but watch out for some of the SocketServer
derivatives in the standard library - they like to "log" by printing
to stdout and you'll need to override that with real logging.

>> * Create a monitor process that checks to see if the pid of the socket
>> server exists, then if it can connect to the socket port, calls a
>> restart on the daemon and exits.
>> * Run the monitor process from a cron job.
> i would run the monitor process as a daemon that
> restarts the socket server after the server exits.
> set up a cron job to check the monitor process is
> running and start if not.

A slightly simpler setup is to have a "conditional start" init script
command for your daemon. Have this run from cron every 1-15 minutes.
It checks the PID file for the daemon and then if that process is
still responding. If the daemon exits then the condstart will restart
it. No need for a second monitor process.


More information about the python-au mailing list