Using Monit to Monitor Custom Daemons

I have a daemon written in PHP. I use the following command to call the daemon

php dojobs.php 

when I call this command, the daemon starts endlessly because the dojobs.php file has the following code

 while(true) { code here } 

I have the following questions:

  • How to use Monit (on a CENTOS linux 5.5 server) to monitor this daemon and restart it if it fails?
  • I have the following code inside the daemon:

    exec ('nohup sendMail.php> / dev / null 2> & 1 and echo $!' ;, $ op);

(how can I make sure that the nohup command above works correctly and that the sendMail.php file actually does its job? SendMail.php is not a daemon, it sends an email and then exits.)

Thank you very much.

+6
source share
1 answer

Not familiar with Monit, so I can not help it. But instead of calling exec() you can use the Process Control (pcntl _ * ()) extension to unblock individual processes and wait for them to return the status code to the parent process to see if the job completed successfully or not.

+2
source

Source: https://habr.com/ru/post/903400/


All Articles