Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have an app that I need to autostart when the OS starts. I am running in a CentOS 6, so I am using a LSB init script placed in /etc/init.d. So far this is fine and working.

Now....besides that, what I would like is that if my app crashes (exits with error), I want that it automatically starts again. Ideally, even defining a max number of tries. In Mac's Info.plist there are the keys KeepAlive Since I already have chkconfig working, I was wondering if there is something I could do with it.

I know there is http://mmonit.com/monit/ but it may be too much for what I need.

share|improve this question
This feature was added to systemd basically because it is such a hassle for admins to implement a third-party solution. If the application doesn't have its own monitoring process, there's nothing that supervises service continuity unless you install and configure something for that purpose. – Bratchley Apr 22 '13 at 16:31
what is the issue with monit ? – Rahul Patil Jun 6 '13 at 15:20

Given you control the init.d script to start this process you might want to just wrap the execution of your process in the init.d script like so:

until myserver; do
    echo "Server 'myserver' crashed with exit code $?.  Respawning.." >&2
    sleep 1

This will lanch your process in an until loop basically forever, each time it dies. Counting etc. could be introduced like this:

until myserver; do
    let cnt=cnt+1
    echo "Server 'myserver' crashed with exit code $?.  Respawning.." >&2
    sleep 1
    [ $cnt = $max ] && exit;
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.