3

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.

smonff
  • 346
  • 2
  • 5
  • 15

2 Answers2

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

Dave M
  • 4,494
  • 21
  • 30
  • 30
Moti
  • 287
  • 1
  • 2
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'"
wuan
  • 31
  • 3