Is it possible to configure my CentOS VPS to continually check to make sure that a php script is running? Currently I'm using the screen php method which works fine, but if it gets terminated somehow, how can I start it backup?

I tried adding the command to /etc/rc.d/rc.local, however this morning I checked, and the script wasn't running.

link|improve this question

25% accept rate
feedback

4 Answers

This task is well suited to a process monitor like Monit.

The monitoring configuration will be made much easier with Monit if your PHP process produces a PID file. An article describing how to use Monit to check and start PHP processes is available here.

link|improve this answer
feedback

You can write a checking script that parses the output of the ps command, looking for your php instance. If it exists, then your script should silently exit; if it does not, then your script should launch your php program, and then write a message to stdout warning that the process was dead and had to be restarted.

Then, add your checking script to your crontab (e.g.)

MAILTO=you@domain.com
*/5 * * * * /path/to/checking-script.sh

In this example, your checking script runs every 5 minutes. If the php process is dead and your checking script relaunches it, then it will also output the formentioned message which will be emailed to you (as an alert).

link|improve this answer
feedback

This task is well suited for some outside monitoring like AlertFox, Pingdom, Monitis,... (all these have free plans).

The approach is always the same: you create a PHP page that checks that the PHO script is running, and the monitoring service calls it periodically:

http://blog.alertfox.com/2011/01/monitoring-disk-space-and-other-status.html

link|improve this answer
feedback

you can use supervisord for this purpose. It is a python application but very simple to setup. Supervisord provides a auto restart directive in its config which will restart the script is case it dies.

you can read more about it on http://phpadvent.org/2009/daemonize-your-php-by-sean-coates

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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