How to run a shell script before restarting a service in Monit in case of a crash
- by Supratik
I am using Monit 5.3.2 in my Linux box. I am monitoring some services using Monit.
I want to run a script before the running the restart command.
I have used the below conditions for the same.
if does not exist for 2 times within 3 cycles then exec "/bin/bash -c 'touch /tmp/somefile'" as uid someuser and gid someuser
if does not exist for 10 cycles then restart
Unfortunately only the restart action is getting executed.
Can anyone please help me to identify why the first rule is not executed ?
Is there are any other way to solve the problem ?