So I have been trying to get Monit to run a script on start of a service. While Monit has no problem restarting the service, I of course want to be alerted when if my service required starting, not just when it is indefinitely down.
Here is my /etc/monit/conf.d/nginx.pid file:
check process nginx with pidfile /var/run/nginx.pid
start program = "/usr/sbin/service nginx start"
stop program = "/usr/sbin/service nginx stop"
if failed host 127.0.0.1 port 8080 then restart
if changed pid then exec "/etc/monit/slack.rb"
if failed host 127.0.0.1 port 8080 then exec "/etc/monit/slack.rb" else if succeeded then exec "/etc/monit/slack.rb"
if cpu is greater than 40% for 2 cycles then exec "/etc/monit/slack.rb" else if succeeded then exec "/etc/monit/slack.rb"
if cpu > 60% for 5 cycles then restart
Right now monit will run my slack.rb script if I change the port to a different port which nginx isn't running on (so it obviously can't connect), but it wont run that when nginx is stopped, but then started by monit. The latter scenario is what I need to work.
Thanks for any help!