Keeping worker process going with Supervisord

Supervisord is a great system for monitoring processes and restarting them when they fail.  For a Web application, a great use is worker processes which monitor message queues and process jobs asynchronously to the UI.

Supervisord can be installed with:

$ apt-get install supervisor

One nice feature is a web interface which allows you to monitor the processes, and manually restart if necessary.  By default it’s turned off, but you can turn by adding the following lines to the /etc/supervisor/supervisord.conf file:

[inet_http_server]
port=9001

The web interface will now be available on port 9001

by default, the configurations for each process we need to monitor are stored in /etc/supervisor/conf.d

you can have multiple configurations in one file, or keep each one separate.  as an example, here is a file i use to keep a worker process running:

[program:worker]
command=/usr/bin/php /usr/share/tock/worker/worker.php
autostart=true
autorestart=true

This automatically starts the process at boot, and also restarts if it fails!

it’s a pretty configurable system, more details can be found at:

http://supervisord.org/