I wrote about how to create php daemon a few months ago. The php daemon works well, except sometimes somehow the php execution stopped, and the daemon failed to restart the php execution.
That’s why i create a bash script, that will restart the php daemon when the php daemon died. I put this bash script in cronjob to be executed each minute.
Firstly, make sure the php daemon always write the output to a log file. This bash script will check when the log file last mofified, if the log was not modified for a few minutes, then the bash script will restart the php daemon.
* * * * * /bin/sh /home/xxx/xxx/daemonchecker.sh >/dev/null 2>&1
Here is the bash script:
current=`date +%s`
last_modified=`stat -c “%Y” /home/xxx/log/daemon.log`if [ $(($current-$last_modified)) -gt 1 ]; then
echo “restart senderdaemon”;
initctl stop senderdaemon
initctl start senderdaemon
else
echo “new senderdaemon”;
fi