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.

EEAA
  • 109,363
  • 18
  • 175
  • 245
Spencer
  • 23
  • 3

4 Answers4

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.

Jodie C
  • 743
  • 6
  • 9
ceejayoz
  • 32,910
  • 7
  • 82
  • 106
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.)

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

JeffG
  • 1,194
  • 6
  • 18
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

Hovertruck
  • 61
  • 1
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