如何使Monit“检查过程”有条件?

我有一个像这样的monit脚本:

check process sidekiq_1 with pidfile /tmp/pids/sidekiq_1.pid start program = "/bin/bash -l -c 'bundle exec sidekiq start" as uid jim and gid jim with timeout 250 seconds stop program = "/bin/bash -l -c 'bundle exec sidekiq stop" as uid jim and gid jim with timeout 120 seconds if cpu usage > 25% for 18 cycles then restart if mem > 1500.0 MB for 18 cycles then restart 

这很好,但是我需要根据触发器文件的存在进行有条件的检查,如下所示:

如果文件/tmp/do_not_start_sidekiq.txt不存在,只执行检查(启动进程)。

通过这种方式,如果我想closures进程并且不再touch /tmp/do_not_start_sidekiq.txt那么我可以touch /tmp/do_not_start_sidekiq.txt ,直到我执行rm /tmp/do_not_start_sidekiq.txt

我将如何改变这个monit脚本来获得这种行为?

用monit处理这个问题的正确方法是“取消监视”这个过程。

一个例子:

 monit unmonitor sidekiq_1 

不会尝试重新启动或报告进程的问题。

您可以通过以下方式恢复对支票的监控:

 monit monitor sidekiq_1 

这些也可以分组或由cron启动。 一个很好的现实生活部署可能在应用程序监视在营业时间和停机时间窗口,由cron控制…

 ################################################################################ # Shutdown Cucumber ################################################################################ 01 15 * * 1-5 monit unmonitor `/bin/hostname` 50 23 * * 0-5 monit -g servers stop all 51 23 * * 0-5 monit -g base stop all 52 23 * * 0-5 monit stop all 

编辑:

如果您需要非特权用户来控制此行为,则可以使用monit unmonitor/monitor命令的/etc/sudoers条目。

就像是:

 jim ALL=NOPASSWD: /usr/bin/monit unmonitor sidekiq_1 

将允许特定的命令由您的无特权用户,吉姆运行。