"monit restart <service>" how do I know when it's done restarting? "monit restart <service>" how do I know when it's done restarting? unix unix

"monit restart <service>" how do I know when it's done restarting?


Monit is a very silent program! In fact, monit commands tend to run and exit immediately because they run in the background! SO ... use the -v switch if you want to see what Monit is doing, and tail -f the log file and the -I if you want it to run in the foreground.

Synchronous Restarting

Use the -I option:

monit -I restart servicename

This will disable restarting in background, which is e.g. needed when your computer boots!

If you want to diagnose problems, add the verbose option -v:

monit -Iv restart servicename

Status Checking

To check the result, you could try several things:

1) Return value of monit

monit -I restart servicenameecho $?

Normally, $? should be zero upon success and non-zero otherwise. However not programs support it and there is no information on the manpage what is the exit status ($?) of monit. Try to test it.

2) Use status or summary commands

monit -I status

or

monit -I status servicename

or

monit -I summary

these commands will return the status on the output. You may select the command that works best for you and parse its output. Or, as in point 1), check the return value $? (it is not mentioned in the manpage).


One can wakeup the monit deamon by just running monit. This should help to reduce the wait to next cycle.

Do tail -f monit.log to see if the restart was successful or if it failed.


You can always use something like this

while test -f pidfile.pid && kill -0 $(cat pidfile.pid);do   sleep 1; done;while ! kill -0 $(cat pidfile.pid); do   sleep 1; done

this script wait while your process is being restarted.