0

How to execute a script as last step, when monit timeout a service?

My config looks like this:

check process php5-fpm with pidfile /var/run/php5-fpm.pid
    start program = "/usr/sbin/service php5-fpm start"
    stop program  = "/usr/sbin/service php5-fpm stop"
    if failed unixsocket /var/run/php5-fpm.sock then restart
    if 3 restarts within 5 cycles then timeout

There is an option to send an email on timeout like this

alert address@hostname only on { timeout }

but how to execute a script, to e.g. send a SMS, on timeout?

Aley
  • 199
  • 2
  • 3
  • 16

1 Answers1

1

You can just exec any executable in an error state with

if 3 restarts within 5 cycles then exec "/usr/sbin/apacheSmsRestart"

and /usr/sbin/apacheSmsRestart beeing (+chmod +x /usr/sbin/apacheSmsRestart)

#!/bin/bash

# Trigger SMS with... literally anything. ;)
curl 'https://smsgateway.example.com/to/1337421337/text/hello+world'

# Do restart
/usr/sbin/service php5-fpm restart

# Exit with last call's exit code
exit $?
boppy
  • 476
  • 2
  • 5