How do I get monit to do multiple actions when a monitored process has failed?

Solution 1:

I would write a small bash script containing the desired event actions. Call that script from Monit.

It's cleaner, more modular and will behave more predictably. The same idea applies to cron jobs.

For instance, from the Monit examples page, would you rather have to support this:

check directory httpd_core with path /var/crash/core if changed timestamp then exec "/bin/bash -c 'if [ /bin/cat /tmp/monit_httpd_core.tmp | head -1 != /bin/ls /var/crash/core/core.httpd* | tail -1 ]; then /usr/bin/gdb -x /etc/gdb.batch /usr/sbin/httpd /bin/ls /var/crash/core/core.httpd* | tail -1 | tee /tmp/monit_httpd_core.tmp | mail -s httpd_crash [email protected] [email protected]; fi'"

or this:

check directory httpd_core with path /var/crash/core   if changed
timestamp then exec script.sh

Where script.sh contains all of the ugliness.