In an older post, we met Gearman. Gearman is a job server that lets you write workers in any language and then let other processes call them. This requires the workers to stay up and running. In other words, they need to run in daemon mode. In the *Nix world, a daemon is a long running process that keeps running in the background. But even daemons will fall. Or worse, they will become zombies.

Lets take a look at a real life scenario. You have a bunch of PHP workers doing some image processing. At some points, you’re bound to see some errors. Some fatal errors or not trapped exceptions will make the worker terminate. What if the script required more memory than PHP was allowed to use? It’ll be a catastrophic event. We need a way to check such cases.

There is one more scenario. Sometimes long running processes stop working but are not shut down cleanly. They leave their traces in the process table. But they are of no use.

In both scenarios, workers will not be able to serve the purposes. We need someway to monitor the daemons. Recently, I’ve been looking for an efficient solution to the problem and I found a few. But later I noticed that, among the choices, “Supervisor” is the most popular and widely noted. Today we’re going to get to know “supervisor”, a process monitor who will track your processes and restart them if necessary. Awesome? Keep reading.

Installing Supervisor

Supervisor was written in Python and packages using the Python setuptools utils. So before we install supervisor, we need to get the Python setup tools installed.

apt-get install python-setuptools

Then we install supervisor itself:

easy_install supervisor

Note: You must have root privilege to do this.

You can dump some sample configuration using:

echo_supervisord_conf > /etc/supervisord.conf

Check out the manual page for more detailed description of the configuration options:

To debug the settings:

supervisord -n

To run supervisor:


That’s it! Happy supervising!