1

Given a config like this:

check host web1 address web1
    if failed host web1 port 80 protocol http
    then exec "/usr/local/bin/failover.sh -h web2"

Can I detect if web1 has returned from failed state, and perform a "fail back" action?

If I were just to detect if it was up, then I would be running the failover command every daemon seconds, and I don't want to do that if I don't have to; it would provide needless log entries and alerts.

crb
  • 7,928
  • 37
  • 53

1 Answers1

1

Thanks to Eric Pailleau for his suggestion which lead to a working answer:

check host web1 address web1
    if failed host web1 port 80 protocol http
        then exec "/bin/bash -c '/usr/bin/test ! -f /var/tmp/web-failover && ( /usr/local/bin/failover.sh -h web2 ; touch /var/tmp/auth-failover )'"
    else if succeeded
        then exec "/bin/sh -c '/usr/local/bin/failover.sh -h web1 ; rm -f /var/tmp/web-failover)'"

It's odd, but if you call /bin/bash on succeeded, monit doesn't seem to run the command. I suspect it thinks it has run the command already, so doesn't bother. It doesn't seem to mind running the first command over and over however!

crb
  • 7,928
  • 37
  • 53