The Action STOP and UNMONITOR don't work at all

Issue #759 resolved
Former user created an issue

I installed monit() through entware on ASUS Router RT-AC68U(ASUS Merlin Firmware) and I find that the Action STOP and UNMONITOR don't work at all!!!

Case

  1. Create a service file /opt/etc/monit.d/test.awake

/opt/etc/monit.d/test.awake:

    check program test path "/opt/etc/monit.d/test/test_start" every 2 cycles
        start program = "/opt/etc/monit.d/test/test_start"
        stop program = "/opt/etc/monit.d/test/test_stop"
        if status != 0 then stop
  1. Create the test scripts "/opt/etc/monit.d/test/test_start" and "/opt/etc/monit.d/test/test_stop"

/opt/etc/monit.d/test/test_start:

    #!/bin/sh
    #
    #TEST='OK'
    TEST='TT'
    #
    if [ ${TEST} == "OK" ]
    then
       echo "$(date +%H:%M:%S)    test_start    exit 0" >> /opt/etc/monit.d/test/log
       exit 0
    else
       echo "$(date +%H:%M:%S)    test_start    exit 1" >> /opt/etc/monit.d/test/log
       exit 1
    fi

/opt/etc/monit.d/test/test_stop:

    #!/bin/sh
    #
    echo "$(date +%H:%M:%S)    test_stop" >> /opt/etc/monit.d/test/log
  1. Run monit reload and start program "test" from the web page.

  2. Finally I get the /opt/etc/monit.d/test/log as below

    16:30:24    test_start    exit 1
    16:30:54    test_start    exit 1
    16:31:24    test_stop
    16:31:54    test_start    exit 1
    16:32:24    test_stop
    16:32:55    test_start    exit 1
    16:33:25    test_stop
    16:33:55    test_start    exit 1
    16:34:25    test_stop
    16:34:55    test_start    exit 1
    16:35:25    test_stop
    16:35:55    test_start    exit 1
    16:36:25    test_stop
    16:36:55    test_start    exit 1
    16:37:25    test_stop
    16:37:55    test_start    exit 1
    16:38:25    test_stop
    16:38:55    test_start    exit 1
    16:39:25    test_stop
    16:39:56    test_start    exit 1
    16:40:26    test_stop
    16:40:56    test_start    exit 1
    # Omitted below
  1. Check the status of service test using monit status test and I get this
    Program 'test'
      status                       OK
      monitoring status            Monitored
      monitoring mode              active
      on reboot                    start
      last exit value              1
      last output                  -
      data collected               Thu, 26 Jul 2018 16:48:41

According to the Documentation

STOP stops the service by calling the service's registered stop method and send an alert. If Monit stops a service it will not be checked by Monit anymore nor restarted again later. To reactivate monitoring of the service again you must explicitly enable monitoring from the web interface or from the console.

It should stop the service at the first "stop" in the log and stop monitoring it. Apparently, the repetition in the log is so abnormal, and the action STOP doesn't work as expected. Neither does the action UNMONITOR.

PS: My monitrc is in the attachments

Comments (4)

  1. Jack Think

    I see that the scripts are displayed messly. I'll add them in the attachments.

    Plus, the action STOP and UNMONITOR could work when I click the button on the webpage or run them in shell, they just could not work in the included service file.

  2. Jack Think

    I give it a test again. It turns out that:

    1. If the code in folder monit.d contains the keyword every like

      check program test path "/opt/etc/monit.d/test/test_start" every 2 cycles

      Action STOP could not behave as the document states

      If Monit stops a service it will not be checked by Monit anymore nor restarted again later.

    2. If the code in folder monit.d doesn't contain the keyword "every" like

      check program test path "/opt/etc/monit.d/test/test_start"

      Action STOP and UNMONITOR could behave as the document states

      If Monit stops a service it will not be checked by Monit anymore nor restarted again later.

  3. Log in to comment