Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I wrote a php daemon using system daemon pear class.

How do I use monit to restart it when it fails?

I have the following code in my monit config file:

check process merge with pidfile /var/www/merge/merge.pid
group 1000
start program = "/etc/init.d/merge start"
stop program = "/etc/init.d/merge stop"
IF CHANGED PID then restart

My goal is solely if the daemon fails (stops running because of an error), I want monit to make it start running again.

share|improve this question
    
So, your config, if the process restarts, the PID changes, then monit sees the PID change, then it restarts it.... :) –  cjc Apr 4 '12 at 11:17
add comment

1 Answer

I'd do this and change ANYTHING_IN_CAPS to your information:

set daemon 120
set logfile syslog facility log_daemon
set mailserver YOUR_MAIL_SERVER
set alert YOUR_EMAIL_ADDRESS


mail-format {
   from: EMAIL_FROM
   reply-to: EMAIL_FROM
   subject: $SERVICE $EVENT at $DATE
   message: Monit $ACTION $SERVICE at $DATE on $HOST: $DESCRIPTION.
      Your watch guard,
      monit
}

set httpd port 2812 and
    use address localhost
    allow localhost

check process merge 
   with pidfile /var/www/merge/merge.pid
   start program = "/etc/init.d/merge start"
   stop program = "/etc/init.d/merge stop"

This will also allow you to issue monit commands such as:

monit summary

You can then see your current status, and you'll be able to receive emails when a restart occurs.

share|improve this answer
    
what does - set httpd port 2812 and use address localhost allow localhost - do? –  Jenis Sam Apr 4 '12 at 5:39
    
Allows you to connect to the monit daemon locally on the server, so you can issue commands such as: "monit summary". –  Brandon Rush Apr 4 '12 at 7:44
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.