另一个选择是使用新贵..它最初是为Ubuntu开发的(默认情况下与Ubuntu一起打包),但它适合于所有Linux发行版。
此方法类似于监督员d和守护进程工具,因为它在系统启动时自动启动守护进程,在脚本完成时自动启动。
如何设置:
创建一个新的脚本文件/etc/init/myphpworker.conf..以下是一个例子:# Infodescription "My PHP Worker"author "Jonathan"# Eventsstart on startup
stop on shutdown# Automatically respawnrespawn
respawn limit 20 5# Run the script!# Note, in this example, if your PHP script returns# the string "ERROR",
the daemon will stop itself.script [ $(exec /usr/bin/php -f /path/to/your/script.php) = 'ERROR' ] && ( stop; exit 1; )end script
启动和停止守护进程:sudo service myphpworker start
sudo service myphpworker stop
检查守护进程是否正在运行:sudo service myphpworker status
谢谢
感谢凯文·范·佐内维尔德我从那里学到了这个技巧。