Rerun a process in Monit if process stops

戏子无情 提交于 2019-12-13 20:50:04

问题


I have a script like this this:

#!/usr/bin/php
<?php
file_put_contents('/home/vagrant/sleep.pid', getmypid());
sleep(9);
exit(0);

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"

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.


回答1:


After playing around more with Monit, I found that I wasn't running Monit properly.

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

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

OR

monit -c monit.conf stop my_role


来源:https://stackoverflow.com/questions/20027254/rerun-a-process-in-monit-if-process-stops

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!