1

I have monit configuration like this:

check process unicorn
with pidfile /tmp/pids/unicorn.0.pid
start program = "/etc/init.d/unicorn start"
stop program = "/etc/init.d/unicorn stop"
restart program = "/etc/init.d/unicorn reload"
if mem is greater than 250.0 MB for 2 cycles then restart
if cpu is greater than 22% for 3 cycles then alert
if cpu is greater than 25% for 2 cycles then restart

But look like whenever monit tries to reload the app (e.g due to memory > 250MB), it issues a stop and then a start, rather than use the restart program. Is there a way to tell monit to run the restart instead? Since issue a stop and a start cause the website to goes down for some moment.

1

I'm seeing the same problem as you reported. I don't know why the 'restart program' is not used to do a restart. However, the workaround I'm using is this:

check process unicorn
with pidfile /tmp/pids/unicorn.0.pid
start program = "/etc/init.d/unicorn start"
stop program = "/etc/init.d/unicorn stop"
if mem is greater than 250.0 MB for 2 cycles then restart
if cpu is greater than 22% for 3 cycles then alert
if cpu is greater than 25% for 2 cycles then exec "/etc/init.d/unicorn reload"

Note that I left the 'if mem' check so that it will do a stop/start. This is because I presume that the reload probably won't help if you have a memory leak thus a stop/start is likely necessary. But tweak as you see fit.

Short of digging into the monit source code and fixing it (or installing a newer version and finding out if it is already fixed) this is probably your best option.

| improve this answer | |
  • It may be that reload is not the same as restart - reload (if it is available/makes sense for the daemon) would re-read the config, in essence, but is not available for everything. restart would cycle through stop and start - I think your config is working because monit is doing an explicit stop then start. – iwaseatenbyagrue Mar 9 '17 at 8:48
0

Which version of monit are you using ?

you syntax for restart seems legit

did you check the web interface to ensure configuration is parsed as attended ?

documentation states

RESTART restarts the service and send an alert. Restart is performed by calling the service's registered restart method or by first calling the stop method followed by the start method if restart is not set.

The method Monit use for restart is to first execute the stop-program, then wait (up to 30s) for the process to stop and then execute the start-program and wait (30s) for it to start.

| improve this answer | |
  • this happened several years ago. We have radical changes in our structure to even bother monit any more. Thank you for this. – Phuong Nguyen Aug 3 '16 at 11:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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