exec actions ignored on process checks

Issue #684 closed
Landry Breuil created an issue

Im trying to have exec action upon failures in process checks, but it seems to me in some circumstances they're ignored. Alerting happens, process restart happens if enabled, but the exec action doesnt take place.

It works fine in a remote host check though, and i can even configure several actions for the same failure (which was my initial goal, ie on failure X; alert (by mail, default), and then two execs for xmpp alerting and sms alerting)

This is with monit 5.23 on OpenBSD.

config excerpt:

check process nginx4 with pidfile /var/run/nginx4.pid
#    start program = "/usr/sbin/rcctl start nginx4"
#    stop program  = "/usr/sbin/rcctl stop nginx4"
#    if failed host 127.0.0.1 port 8004 protocol http request "/monit" content = "nginx4" then alert
    if failed host 127.0.0.1 port 8004 protocol http request "/monit" content = "nginx4" then exec "/usr/bin/touch /tmp/nginx4-process"


check host localnginx with address 127.0.0.1
    if failed port 8004 protocol http request "/monit" content = "nginx4" then exec "/usr/bin/touch /tmp/localhost-nginx4"
    if failed port 8004 protocol http request "/monit" content = "nginx4" then exec "/usr/bin/touch /tmp/localhost-nginx4double"

monit -v parses it as:

Process Name          = nginx4                          
 Pid file             = /var/run/nginx4.pid                                  
 Monitoring mode      = active                                                                                          
 On reboot            = start
 Existence            = if does not exist then restart
 Port                 = if failed [127.0.0.1]:8004/monit type TCP/IP protocol HTTP with timeout 5 s then exec '/usr/bin/touch /tmp/nginx4-process'
...
Remote Host Name      = localnginx
 Address              = 127.0.0.1
 Monitoring mode      = active
 On reboot            = start
 Port                 = if failed [127.0.0.1]:8004/monit type TCP/IP protocol HTTP with timeout 5 s then exec '/usr/bin/touch /tmp/localhost-nginx4double'
 Port                 = if failed [127.0.0.1]:8004/monit type TCP/IP protocol HTTP with timeout 5 s then exec '/usr/bin/touch /tmp/localhost-nginx4'

I would expect 3 files to be created under /tmp, and to receive 3 mails.

If i kill the daemon, the exec action/connection test for the process isnt done :

$doas rcctl stop nginx4
nginx4(ok)

Nov  2 18:33:47 c64 monit[51163]: 'nginx4' process is not running
Nov  2 18:33:47 c64 monit[51163]: 'nginx4' trying to restart
Nov  2 18:33:47 c64 monit[51163]: 'localnginx' failed protocol test [HTTP] at [127.0.0.1]:8004/monit [TCP/IP] -- Connection refused
Nov  2 18:33:47 c64 monit[51163]: 'localnginx' exec: '/usr/bin/touch /tmp/localhost-nginx4double'
Nov  2 18:33:47 c64 monit[51163]: 'localnginx' failed protocol test [HTTP] at [127.0.0.1]:8004/monit [TCP/IP] -- Connection refused
Nov  2 18:33:47 c64 monit[51163]: 'localnginx' exec: '/usr/bin/touch /tmp/localhost-nginx4'

and only two files are created under /tmp.

But i do receive 3 mails for the failed tests. From the documentation, it isnt 100% clear to me whether it should work, or if the connection checks arent supposed to be done if the process doesnt exist and has already failed. Should the exec be moved to a 'if does not exist' test instead ? Is it me not understanding the documentation right ?

Comments (2)

  1. Tildeslash repo owner

    If the port connection test is defined in the 'check process' context, monit will skip the connection test when the process doesn't exist (as it assumes the connection test will fail if the process is not running).

    If you need to exec the script if the process doesn't exist, you need to set the 'if does not exist' rule.

  2. Log in to comment