restart instead of start when a process is not running

Issue #35 resolved
Former user created an issue

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)

  1. Tildeslash repo owner

    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.

  2. plutino

    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
    
  3. Tildeslash 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.

  4. Tildeslash repo owner

    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).

  5. Samuel Reed

    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 the start 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, not restart. If not, we have a regression.

  6. Lutz Mader

    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

  7. Samuel Reed

    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.

  8. Log in to comment