restart instead of start when a process is not running
We have recently upgrade from monit 5.3 to 5.8, but only find out that our background jobs are all broken. We identify that the issue was caused by a change of behavior of monit. In 5.3, when monit detects that a process is not running, it will start the process; while in 5.8, it will restart the process, which involves a stop before start.
While one part of the issue is that our app doesn't handle stop properly, but on the other part, is this an intended change in monit or not? It doesn't not make sense to try to stop a non-existing process before start it.
Comments (11)
-
repo owner -
repo owner -
assigned issue to
-
assigned issue to
-
repo owner - changed status to invalid
Closing the issue - it's configuration problem, not bug,
-
We don't have 'restart program' in config for either versions. In monit log, only "start' action is done in 5.3; but it will first do 'stop' then 'start' in 5.8.
example log in 5.3:
[UTC Nov 7 06:44:31] error : 'background_worker_0' process is not running [UTC Nov 7 06:44:31] info : 'background_worker_0' trying to restart [UTC Nov 7 06:44:31] info : 'background_worker_0' start: /usr/bin/sudo
example log in 5.8:
[UTC May 1 05:53:27] error : 'background_worker_0' process is not running [UTC May 1 05:53:27] info : 'background_worker_0' trying to restart [UTC May 1 05:53:27] info : 'background_worker_0' stop: /usr/bin/sudo [UTC May 1 05:53:27] info : 'background_worker_0' start: /usr/bin/sudo
-
repo owner - changed status to open
We agree with you that the old behaviour is much preferable and correct. It is unclear why this was introduces in the first place and we'll revert this so that start is start not restart.
-
repo owner - changed version to 5.9
-
repo owner - changed status to resolved
The problem was introduced in Monit 5.7 ... fixed the restart action (which is triggered when process is not running) to skip stop if process is not running.
The fix will be part of next Monit release (5.8.1 or 5.9).
-
repo owner - removed version
Removing version: 5.9 (automated comment)
-
This behavior is back in 5.23. We had a service quit, but upstart caught it & started it before monit did. Monit was slower to react and called the
restart program
stanza rather than thestart program
stanza, causing it to start & stop again, which is undesirable.We don't want to remove the
restart program
stanza because it is quicker than stop/start when we use it. And the docs say:If the pid-file does not exist or does not contain the PID number of a running process, Monit will call the entry's start method if defined.
So is this behavior intentional? If so, the docs should be updated and there should be a way to indicate that you only want
start
, notrestart
. If not, we have a regression. -
Hello Samuel,
I use a start only by an additional test, the start will delayed to five cycles also.check process ... start program “/usr/local/etc/monit/scripts/wlpserv.sh start" stop program “/usr/local/etc/monit/scripts/wlpserv.sh stop" restart program “/usr/local/etc/monit/scripts/wlpserv.sh restart" if not exist for 5 cycles then start :
I don’t know upstart, but systemd and launchd restart programs too.
Lutz
p.s.
See “EXISTENCE TESTS“, https://mmonit.com/monit/documentation/monit.html -
Confirmed this can be fixed by simply adding
if not exist then start
, no need to specify cycles. I still think this should be default behavior though. - Log in to comment
The action which is performed by Monit when process is not running was always "restart", but since there was no standalone "restart program" (until Monit 5.7), stop+start sequence was used. During stop, Monit looked up for the process and if it was not running already, the stop was skipped.
The "restart program" is called only when it is defined - if it's not defined, then the traditional stop+start programs are called => if your "restart program" is invalid, just remove it from Monit configuration and reload Monit ... it will fallback to original behaviour.