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.
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