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 servicename
echo $?
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).