简体   繁体   English

“monit restart <service> “我怎么知道什么时候重启?

[英]“monit restart <service>” how do I know when it's done restarting?

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". 我们的sysadmin最近切换到使用monit,所以现在当我想重新启动服务时,我应该使用“monit restart <servicename>”而不是“/etc/init.d/ <servicename> restart”。

However, the monit command, when successful, produces no output and returns immediately. 但是,monit命令在成功时不会产生任何输出并立即返回。 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. 在我等待的时候,我不喜欢一遍又一遍地输入“ps aux | grep <myservicename>”。

Is there a way to make monit restart my service immediately? 有没有办法让monit立即重启我的服务?

Is there a way to make monit, or perhaps a wrapper around monit, block until the restart is finished? 有没有办法让monit,或者monit的包装器阻塞,直到重启完成?

Is there a way to make monit tell me that the restart was successful, or else that it failed? 有没有办法让monit告诉我重启成功,否则它失败了?

Monit is a very silent program! Monit是一个非常安静的计划! In fact, monit commands tend to run and exit immediately because they run in the background! 事实上,monit命令往往会立即运行和退出,因为它们在后台运行! 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. 所以......如果你想看看Monit正在做什么,请使用-v开关,如果你想让它在前台运行,请使用tail -f日志文件和-I

Synchronous Restarting 同步重启

Use the -I option : 使用-I选项

monit -I restart servicename

This will disable restarting in background, which is eg needed when your computer boots! 这将禁用后台重启,例如计算机启动时需要重启!

If you want to diagnose problems, add the verbose option -v : 如果要诊断问题,请添加详细选项-v

monit -Iv restart servicename

Status Checking 状态检查

To check the result, you could try several things: 要检查结果,您可以尝试以下几种方法:

1) Return value of monit 1)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 . 但是没有计划支持它,并没有对任何信息手册页什么是退出状态( $?monit Try to test it. 尝试测试一下。

2) Use status or summary commands 2)使用statussummary命令

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 $? 或者,如第1点),检查返回值$? (it is not mentioned in the manpage). (在联机帮助页中没有提到)。

One can wakeup the monit deamon by just running monit . 人们可以通过运行monit唤醒monit deamon。 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. 执行tail -f monit.log以查看重启是否成功或是否失败。

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 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM