I have a custom service that I want to monitor with monit. When the process fails I want to copy the log to a shared file system and restart the service. Something like the following but I am not not sure what. Any hints would be appreciated.
check process pipeline with pidfile /var/run/pipeline.pid
start program = "/sbin/start pipeline"
stop program = "/sbin/stop pipeline"
if 10 restarts within 10 cycles then timeout
# Not sure what to write next
if <service has failed>
restart and
exec "/bin/bash -c 'cp /var/log/upstart/pipeline.log /nfs/logs/`hostname`.`date +'%m-%d-%Y_%H.%M.%S'`.log'"
Best Answer
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:
or this:
Where
script.sh
contains all of the ugliness.