Monit and multiple actions: chaining commands in Monit restart command

configurationmonitservice

After some researches, it occurs that even if I can find some talks about multiple actions when restarting a service, it also seems it it not really possible to achieve :

 if failed port 80 and protocol http
     then exec /home/sweet/script.pl
     and restart

When declaring the restart command for a service in the monitrc configuration file, is it ok to try something like this :

restart program = "perl /home/sweet/crazy-stuff.pl && /etc/init.d/server restart"

As monit -t don't mention any error I prefer to ask before to do bad things.

Best Answer

You should use exec and a bash subshell, for example:

exec "/bin/bash -c '/etc/init.d/server restart && perl /home/sweet/script.pl'"

However, best practice recommends using a single script for all your actions ( meaning include the init.d restart command into your shell script.)