首页 > 解决方案 > 监控只执行一次

问题描述

Monit 当前正在执行一次。我可以在日志文件中看到它每个周期都会检查一次,但是,当我重新加载 monit 时,执行只会发生一次。

check host somehost with address example.com
# every "* 8-19 * * 1-5"
 if failed
    port 443
    protocol https
    and certificate valid > 1095 days
 then exec "/var/local/bin/mtCert.sh"

标签: monit

解决方案


基于Monit triggers,它基本上只跟踪变化

所以如果配置的状态没有改变,monit默认不会再次触发脚本。请参阅 Monit Changelog中有关 5.16.0 的注释:

已修复: exec 操作现在只在状态更改时执行一次,与警报操作相同。如果错误仍然存​​在,新的重复选项可用于在给定数量的周期后重复执行操作。句法:

if <test> then exec <script> [repeat every [x] cycle(s)]

如果您想要旧的行为,请使用“重复每个循环”。例子:

if failed port 1234 then exec "/usr/bin/myscript.sh" repeat every cycle

因此,如果您实际上需要多次调用脚本,只需添加repeat

check host somehost with address example.com
# every "* 8-19 * * 1-5"
  if failed
    port 443
    protocol https
    and certificate valid > 1095 days
  then exec "/var/local/bin/mtCert.sh"
  and repeat every 10 cycles

推荐阅读