How can I automatically restart a process after it terminates?

I've got a golang program that I want to restart after it terminates on a Debian Squeeze box. The thing is serving HTTP behind an Apache 2 mod_proxy setup. I don't expect the process to fail, but I'd like to have some insurance against it.

On Ubuntu I would have used upstart to keep the process alive. Debian doesn't like Upstart from what I understand as it is an init replacement.

Is there an alternative which restarts one or more processes after they terminate that works on Squeeze and plays nice with init?


The best way to go for it are the daemontools. They allow you to monitor and respawn processes.

See the documentation on their website: http://cr.yp.to/daemontools.html


supervise is a lightweight, efficient alternative. Under debian it is packaged in daemontools. You can also read this related question, which lists some supervise criticisms, and mentions restartd as another possibility.

Finally, if you want something incredibly easy to setup, I've had great success with monit. It is also packaged in Debian.