使用shell脚本重新启动php脚本 [英] restart a php script using shell script
问题描述
我正在使用Shell脚本来监视php脚本的工作.我的目的是使该php脚本不应该休眠/终止,并且必须始终在运行.我使用的代码是-
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 & )
现在,如果php脚本被终止(进程状态代码T),这种想法将无法解决.任何解决这种情况的想法.这样的进程可以永久终止,然后重新启动.
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.
推荐答案
如果脚本在终止后退出,或者崩溃了并且需要重新启动,则可以使用简单的shell脚本来解决. /p>
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.
#!/bin/bash
# runScript.sh - keep a php script running
php -q -f ./cli-script.php -- $@
exec $0 $@;
exec $0
使用指定的参数重新运行Shell脚本.
The exec $0
re-runs the shell script, with the parameters it was given.
要在后台运行,您可以nohup runScript.sh
或通过init.d脚本,新贵,runit或超级用户等来运行它.
To run in the background you can nohup runScript.sh
or run it via init.d scripts, upstart, runit or supervisord, among others.
这篇关于使用shell脚本重新启动php脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!