5

I would like to know whether it is possible to add a delay between stop/start methods. This is mainly because it requires at least 10 secs delay to close all open socket connections and close the server socket gracefully to start again.

This is my monit script

set logfile /var/log/monit.log
check process test.sh with pidfile /home/svcs/test/pid/app.pid
start program = "/etc/init.d/test.sh start" with timeout 60 seconds
stop program = "/etc/init.d/test.sh stop" with timeout 60 seconds
if failed host xx.xx.com port 443
type tcpSSL protocol http with timeout 15 seconds retry 3 then restart
alert xx@xx.com

Thanks

kakopappa
  • 151
  • 1
  • 4

2 Answers2

2

The command is

sleep

followed by a value in seconds.

So add sleep 10 between the lines and that should do it.

Note that it must be an integer value on solaris; on general linux decimals work too (you can put 10.15 or something else).

Overmind
  • 2,970
  • 2
  • 15
  • 24
  • 1
    between which lines? between "start program" and "stop program" inside the monit config will not work, because there is no "sleep" command allowed by monit. So I see a chance with inside the path to the start script like `start program = "sleep 10; /etc/init.d/test.sh start"` – Achim Mar 08 '17 at 23:08
  • @Achim You're correct- the answer is incomplete/incorrect - this is a monit config file not a shell script. Your example will work, though. Optionally, you could just specify a custom shell script that does that (or more). Don't forget to specify your interpreter: `#!/bin/sh` (or whatever) if you use a script. I would also use full paths on everything. `/bin/sleep`. But that's me. – B. Shea Aug 19 '18 at 14:22
  • Also note: "In the case of a process check, Monit will wait up to 30 seconds for the start/stop action to finish before giving up and report an error. You can override this timeout using the TIMEOUT option or globally using the set limits." : https://mmonit.com/monit/documentation/monit.html#SERVICE-METHODS -- Therefore if you sleep for too long it will timeout - unless you fix that too. Consider the following: `start program = "/bin/sleep 100; /usr/sbin/service apache2 start" with timeout 200 seconds` – B. Shea Aug 19 '18 at 14:44
1

Example:

 start program = "/bin/sleep 90; /etc/init.d/apache2 start" with timeout 110 seconds

/bin/sleep is what you want.

You could also specify a single shell script in place of what is in quotes to do that:

 start program = "/home/user/scripts/my_custom_start.sh" with timeout 110 seconds

my_custom_start.sh:

 #!/bin/sh
 /bin/sleep 90
 /etc/init.d/apache2 start

If you use a script in this manner, do not forget to specify your interpreter: #!/bin/sh (or whatever) as per documentation and the correct permissions. Then simply add the sleep statement to the shell script where you need it along with your "start" process call(s). Do not forget the UID/GID you want to execute as (if needed).

Consult documentation here:

https://mmonit.com/monit/documentation/monit.html#SERVICE-METHODS

B. Shea
  • 959
  • 10
  • 22