Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 1

up vote 0 down vote accepted

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!

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.