As a way to build a poor-man\'s watchdog and make sure an application is restarted in case it crashes (until I figure out why), I need to write a PHP CLI script that will be
I'd use pgrep to do this (caution, untested code):
exec("pgrep lighttpd", $pids);
if(empty($pids)) {
// lighttpd is not running!
}
I have a bash script that does something similar (but with SSH tunnels):
#!/bin/sh
MYSQL_TUNNEL="ssh -f -N -L 33060:127.0.0.1:3306 tunnel@db"
RSYNC_TUNNEL="ssh -f -N -L 8730:127.0.0.1:873 tunnel@db"
# MYSQL
if [ -z `pgrep -f -x "$MYSQL_TUNNEL"` ]
then
echo Creating tunnel for MySQL.
$MYSQL_TUNNEL
fi
# RSYNC
if [ -z `pgrep -f -x "$RSYNC_TUNNEL"` ]
then
echo Creating tunnel for rsync.
$RSYNC_TUNNEL
fi
You could alter this script with the commands that you want to monitor.