11

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?

4
  • Would you please rephrase your question? Is it that you want to restart a process after it has been terminated?
    – mailq
    Aug 6, 2011 at 9:47
  • I'd like to restart a process automatically if it faults or terminates itself.
    – Deleted
    Aug 6, 2011 at 9:48
  • 2
    The traditional init program does precisely this. Why people thought it would be a good idea to use init to run a shell script invoking a shell script that starts another process that does the same thing, but without an automatic kernel panic and reboot should that process ever fail, is completely beyond me. Aug 6, 2011 at 14:53
  • That's a fair point. I'll investigate just using init as well. I'm packaging the software using dpkg so creating init scripts shouldn't be a hardship.
    – Deleted
    Aug 6, 2011 at 17:07

5 Answers 5

10

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

2
  • 1
    Thanks - that's just what I'm after. DJB = good as a rule. I should actually have remembered that existed what with spending 5 years looking after qmail!
    – Deleted
    Aug 6, 2011 at 11:09
  • Same with me, except that I used to look after djbdns for quite some time.
    – mr.b
    Feb 12, 2013 at 11:14
10

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.

1
  • 2
    daemontools is awesome; monit is a freaking nightmare of "why the hell won't you start?!?" frustration.
    – womble
    Aug 6, 2011 at 10:19
2

supervise or monit are good for keeping a single process alive. Since you ask for keeping "one or more" processes alive, I would like to plug supervisord. It is certainly overkill for managing a single process, but if you need to keep track of multiple processes it may be your thing.

2

One option is to use /etc/inittab instead of putting your script in /etc/init.d/.

You simply add an entry in the following format:

<jobname>:<runlevels>:respawn:<command>

Unfortunately this means you cannot use the normal start/stop/restart init commands, but it should ensure your script is running all the time.

2

The cross distribution way of handling process re-starts is with cron and a simple script. You can see a writeup here How to keep a job running in Linux

The script looks something like

#!/bin/bash 
# make-run.sh 
# make sure a process is always running.  
# Add the following to the crontab (i.e. crontab -e)
# */5 * * * * /home/path_to_make_run/make-run.sh

process=servermonitoringhq 
makerun="/home/path_to_the_job_you_want_running/runjob.sh"  

if pgrep $process > /dev/null         
then                 
  exit         
else         
  $makerun &         
fi 

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .