问题描述
我有一个这样的脚本:
#!/usr/bin/php
<?php
file_put_contents('/home/vagrant/sleep.pid', getmypid());
sleep(9);
exit(0);
我想编写我的 Monit 配置,以确保此应用程序始终运行.这是我的监控配置:
I want to write my Monit config so it makes sure this application is always running. This is my monit config:
set daemon 5
check process program with pidfile /home/vagrant/sleep.pid
start program = "/usr/bin/php /home/vagrant/myphp.php"
但是在我的程序退出后,Monit 不会尝试再次运行它.这有点道理,但我想知道是否有任何方法可以告诉 Monit 重新运行该过程.
But after my program exits Monit doesn't try to run it again. It kinda make sense but I was wondering if there is any way to tell Monit to rerun the process.
推荐答案
在与 Monit 玩了更多次之后,我发现我没有正确运行 Monit.
After playing around more with Monit, I found that I wasn't running Monit properly.
首先,您需要将以下配置添加到您的 monit 文件中:
First you need to add the following config to your monit file:
set httpd port 2812 and allow monit:monit
set daemon 5
check process program with pidfile /home/vagrant/sleep.pid
start program = "/usr/bin/php /home/vagrant/myphp.php"
然后使用以下命令运行监视器:
Then run the monit with this command:
monit -c monit.conf
现在Monit在后台运行,如果它死掉了,你可以重新启动或启动特定的程序:
Now Monit runs in the background and rerun the process if it dies, you may restart or start specific program with :
monit -c monit.conf start all
或
monit -c monit.conf stop my_role
这篇关于如果进程停止,则在 Monit 中重新运行进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!