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.

2 Answers 2

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.

1
  • 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. Mar 9, 2017 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.

1
  • this happened several years ago. We have radical changes in our structure to even bother monit any more. Thank you for this. Aug 3, 2016 at 11:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .