我正在写一个lsb init脚本(不可否认的是我从未做过的事情),它启动了一个自我守护的PHP脚本. PHP脚本就像这样开始:
然后在init脚本中启动它:
–daemon标志导致PHP脚本分离&作为守护进程本身运行,而不是依靠start-stop-daemon来分离它.
这是它(尝试)在init脚本中停止它的方式:
问题是,当我尝试通过init脚本停止时,它给了我:
快速查看ps告诉我,即使PHP脚本本身是可执行的,它也可以作为PHP< script>运行.而不是脚本名称本身,这使得start-stop-daemon看不到它. PID文件甚至正在生成,但似乎忽略它并尝试通过进程名称查找kill.
- $ps ax | grep '/path/to/executable/PHP-script.PHP'
- 2505 pts/1 S 0:01 PHP /path/to/executable/PHP-script.PHP --daemon --pid-file /var/run/blah/blah.pid --other-PHP-script-args
- 2507 pts/1 S 0:00 PHP /path/to/executable/PHP-script.PHP --daemon --pid-file /var/run/blah/blah.pid --other-PHP-script-args
- 2508 pts/1 S 0:00 PHP /path/to/executable/PHP-script.PHP --daemon --pid-file /var/run/blah/blah.pid --other-PHP-script-args
- 2509 pts/1 S 0:00 PHP /path/to/executable/PHP-script.PHP --daemon --pid-file /var/run/blah/blah.pid --other-PHP-script-args
- 2518 pts/1 S 0:01 PHP /path/to/executable/PHP-script.PHP --daemon --pid-file /var/run/blah/blah.pid --other-PHP-script-args
- $cat /var/run/blah/blah.pid
- 2518
正确停止:
- start-stop-daemon --stop --oknodo --pidfile $PIDFILE