Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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
add comment

4 Answers 4

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
add comment

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

share|improve this answer
add comment

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
add comment

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
add comment

Your Answer

 
discard

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.