0

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.

4 Answers 4

1

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.

4
  • This link seems to be dead now. Apr 28, 2014 at 6:41
  • @GauravGupta Archive.org can usually help you out. https://web.archive.org/web/20100615000000*/http://bipinb.com/monitoring-a-daemon.htm
    – ceejayoz
    Apr 28, 2014 at 13:57
  • True, already checked that. "Wayback Machine doesn't have that page archived." Apr 29, 2014 at 4:25
  • @GauravGupta It works fine. SO's adding a space in the URL though - doesn't like the *.
    – ceejayoz
    Apr 29, 2014 at 5:24
0

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.)

[email protected]
*/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).

0

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

0

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

You must log in to answer this question.

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