i am using shell script to monitor the working of a php script. My aim is that this php script should not sleep / terminated and must always be running.The code i used is –
ps aux | grep -v grep | grep -q $file || ( nohup php -f $file -print > /var/log/file.log & )
now this idea would not work for cases if the php script got terminated(process status code T). Any idea to handle that case. can such processes be killed permanently and then restarted.
If the script is exiting after it’s been terminater, or if it crashes out, and needs to be restarted, a simple shell script can take care of that.
The
exec $0re-runs the shell script, with the parameters it was given.To run in the background you can
nohup runScript.shor run it via init.d scripts, upstart, runit or supervisord, among others.