Monit's documentation states the following for the restart action :
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.
I'm monitoring some processes and I recently found out that the stop method is not called even though the restart method is not set. Here's the configuration :
check process myProcess matching "myProcess"
start program = "/etc/init.d/myProcess start"
stop program = "/etc/init.d/myProcess stop"
if not exist then restart
It crashed yesterday and the log said :
[CET Nov 9 12:30:36] error : 'myProcess' process is not running
[CET Nov 9 12:30:36] info : 'myProcess' trying to restart
[CET Nov 9 12:30:36] info : 'myProcess' start: '/etc/init.d/myProcess start'
[CET Nov 9 12:30:36] debug : Starting myProcess ...
myProcess is already running ... //The output of the init.d script. The process does not start since the PID file was not deleted by the stop method
[CET Nov 9 12:31:06] error : 'myProcess' failed to start (exit status 0) -- '/etc/init.d/myProcess start': Starting myProcess ...
myProcess is already running ...
Monit calls the start method which fails since the init.d script looks for the PID file that wasn't deleted since the process crashed. However, according to the documentation, Monit should first call the stop method (which in my case would delete de PID file) and then call the start method.
Is there a way to have this behavior in Monit or should I modify all my init.d scripts ?
The process was not found by Monit therefore only start is used to restart the process. You can use the pidfile to do the check.
Some more information are available from https://mmonit.com/monit/documentation/monit.html#Process
To get some more additional information you can start Monit with "monit -vv" or "monit -vv -I".
I found a workaround to this. As a restart command, I stop and start the process manually :