You could run monit doing like this in the config:
check process spawn-fcgi with pidfile /var/run/spawn-fcgi.pid
start program = "/etc/init.d/spawn-fcgi start"
stop program = "/etc/init.d/spawn-fcgi stop"
if failed host localhost port 80 protocol HTTP request /test.php then restart
if 5 restarts within 5 cycles then timeout
depends on nginx
check process nginx with pidfile /var/run/nginx.pid
start program = "/etc/init.d/nginx start"
stop program = "/etc/init.d/nginx stop"
if failed host localhost port 80 protocol HTTP request /token.html then restart
if 5 restarts within 5 cycles then timeout
the test.php is just a php file that does echo 'OK'
Of course I supose you already have a spawn-fcgi init script and a PID file.
Best Answer
Run it with option
-P
to store the PID in some temp file. For example:Then you can kill it by this pid: