문제

Our sysadmin recently switched to using monit, and so now when I want to restart a service, I'm supposed to use "monit restart <servicename>" instead of "/etc/init.d/<servicename> restart".

However, the monit command, when successful, produces no output and returns immediately. It seems like it doesn't actually do the restart until after it's next cycle.

I'm restarting the service because I made changes to it. I don't want to test my changes against the old instance. So I need to know when the restart is complete. I also would prefer it do the restart when I tell it to, and not when it gets around to it. I don't enjoy typing "ps aux | grep <myservicename>" over and over again while I wait.

Is there a way to make monit restart my service immediately?

Is there a way to make monit, or perhaps a wrapper around monit, block until the restart is finished?

Is there a way to make monit tell me that the restart was successful, or else that it failed?

도움이 되었습니까?

해결책

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

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top