在认为事情已经死了之前,让监视等待更长时间

我试图启动一个程序(Resque),但是在写入pidfile之前需要一些时间。 因此,我认为Monit认为程序在第一个程序的pid文件被写入之前还没有启动并启动一两个程序。

我如何推迟Monit再次检查,只是为了这个过程? 或者我应该以另一种方式解决这个问题?

    我如何推迟Monit再次检查,只是为了这个过程?


    你试图达到的目标可以通过monit的“ 服务轮询时间 ”function来完成

    Monit文档说

    服务定期检查

    set daemon n 

    声明。 检查按照与.monitrc文件中写入的顺序相同的顺序执行,除非在服务之间设置了依赖关系,在这种情况下,服务层次结构可以交替检查的顺序。

    定制服务调查的方法之一是

    1. 自定义间隔基于轮询周期长度倍数

    每个[数字]周期

    例:

     check process resque with pidfile /your/app/root/tmp/pid/resque.pid every 2 cycles 

    或者我应该以另一种方式解决这个问题?


    我也做了初始的尝试,用monit监视resque作业,因为monit是一个非常轻量级的守护进程,但最终与GOD一起解决。 我知道,我知道上帝相比monit来说更需要资源,但是如果复活,我们发现它是一个很好的匹配。

    您可以检查特定服务的时间间隔不同于默认时间…

    请参阅Monit文档中的SERVICE POLL TIME 。

    Resque程序的一个例子是检查不同数量的周期:

     check process resque with pidfile /var/run/resque.pid every 5 cycles 

    或从示例部分:

     Some servers are slow starters, like for example Java based Application Servers. So if we want to keep the poll-cycle low (ie < 60 seconds) but allow some services to take its time to start, the every statement is handy: check process dynamo with pidfile /etc/dynamo.pid every 2 cycles start program = "/etc/init.d/dynamo start" stop program = "/etc/init.d/dynamo stop" if failed port 8840 then alert 

    或者你可以利用cron风格的检查。

     check process resque with pidfile /var/run/resque.pid every 10 * * * * 

    或者如果遇到启动缓慢的情况,则可以在service start命令中延长超时时间:

     check process apache with pidfile /var/run/httpd.pid start program = "/etc/init.d/httpd start" with timeout 90 seconds 

    您还可以检查是否有X次直线失败:

      if failed port 80 for 10 cycles then alert 

    或者在Y民调中X次:

      if failed port 80 for 3 times within 5 cycles then alert 

    或两者:

      check filesystem rootfs with path /dev/hda1 if space usage > 80% for 5 times within 15 cycles then alert if space usage > 90% for 5 cycles then exec '/try/to/free/the/space' 

    ( 从这里 )

    我的团队成员提出了一个相当聪明的解决scheme, 允许monit频繁(每分钟)检查一次 ,但一旦它试图重新启动服务(大约需要10分钟), 它将在尝试启动之前等待指定的宽限期再次。

    这样可以防止在检查之间等待时间过长,这与慢启动相比对客户的影响要大得多。 它通过使用作为标志的中间脚本来工作,以指示monit已经从最后一次失败中采取行动。

     check host bamboo with address bamboo.mysite.com if failed port 443 type tcpSSL protocol http and status = 200 and request /about.action for 3 cycles then exec "/bin/bash -c 'ps -ef | grep -v "$$" | grep -v "grep" | grep restartBamboo.sh >/dev/null 2>&1; if [ $? -ne 0 ]; then /opt/monit/scripts/restartBamboo.sh; fi'" 

    如果竹(慢启动Web应用程序)连续3分钟停机,则重新启动,但只有在重新启动脚本尚未运行的情况下。

    被调用的脚本有一个特定的睡眠,等待时间较长,然后是最慢的服务启动时间(在我们的情况下,我们预计在10秒内完成,所以我们睡15)

     #!/bin/bash echo "Retarting bambo by calling init.d" /etc/init.d/bamboo stop echo "Stopped completed, calling start" /etc/init.d/bamboo start echo "Done restarting bamboo, but it will run in background for sometime before available so, we are sleeping for 15 minutes" sleep 900 echo "done sleeping" 

    当前版本的Monit(5.16)支持启动脚本的超时,语法如下:

      <START | STOP | RESTART> [PROGRAM] = "program" [[AS] UID <number | string>] [[AS] GID <number | string>] [[WITH] TIMEOUT <number> SECOND(S)] 

    文档状态:

    在进行stream程检查的情况下,Monit会在放弃和报告错误之前等待最多30秒的时间来完成启动/停止操作。 您可以使用TIMEOUT选项覆盖此超时。

    这是什么“超时”值将做什么。