Server Fault is a question and answer site for system and network administrators. 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 a Debian box, on the machine I have a php script running.

How I can monitor it, and when the php script dies, restart it automatically ?

share|improve this question
Is it a standalone php script or part of a web site running on a webserver? – chmeee May 27 '10 at 10:16

If it is a standalone PHP script, you might be interested in daemontools (by D.J. Bernstein, of QMail fame). Instead of starting services directly, the supervise daemon take care of starting those. Whenever it detects that one of the services abort for whatever reason, it attempts to restart it.

share|improve this answer
daemontools is awesome. – Warner May 27 '10 at 15:03

Monit is also a good tool for that kind of things.

share|improve this answer

You could also run a cron job every minute, and kick-off the script if it's not in the output of something like ps aux | grep <scriptname> | grep -v grep

share|improve this answer

You can use duende, of maradns fame. From its man page:

Should the parent duende process a HUP signal, duende will restart the child process. Should the daemonized or logging process received an untrapped HUP signal or exit with an exit code of 8, duende will restart the process. Should the daemonized or logging process exit for any other reason, duende will send the logger process a TERM signal and exit. Should the duende parent process receive a TERM or INT signal, duende sends all of its children TERM signals, then exits.

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.