2

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.

3

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.)

| improve this answer | |
0

how about this format

  blabla... exec "/bin/sh -c 'foo=$(mktemp) && tee $foo <<-EOF
# create the bash script then execute it

/etc/init.d/server restart
perl /home/sweet/script.pl

# and any other commands as you wish

EOF
/bin/bash $foo'"

if you want auto delete, append /bin/rm $foo after /bin/bash $foo

...
EOF
/bin/bash $foo; /bin/rm $foo'"
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.