【问题标题】:monit call exec on process recovery监控进程恢复时调用 exec
【发布时间】:2016-12-19 10:31:35
【问题描述】:

我想做的事情如下:

  • 如果 process-x 失败(重新启动)然后执行 cmd-x
  • 如果恢复则执行 cmd -y

对于通过电子邮件发出的警报,默认情况下会在恢复时发送通知。但是,对于 exec 方法,我找不到使这项工作正常进行的方法。如果我在监视器中尝试这个:

check process proc_x with pidfile /var/run/proc_x.pid
   start program = "/bin/sh -c '/etc/init.d/Sxxproc_x start'"
   stop  program = "/bin/sh -c '/etc/init.d/Sxxproc_x stop'"
   if 3 restarts within 5 cycles then exec "<some error cmd>"
   else if succeeded then exec "<some restore cmd>"

这会导致“语法错误'else'”。如果我删除 else 行,则会按预期调用错误命令。显然,'else' 不能用于 restarts 测试。但是如何添加执行命令是程序启动成功还是恢复?

【问题讨论】:

    标签: monit


    【解决方案1】:

    感谢这个话题的回答,我找到了解决方案:

    get monit to alert first and restart later

    if not exist for ...”和相应的“else”让我报告了恢复。错误报告是单独的。我现在的监控代码:

    check process proc_x with pidfile /var/run/proc_x.pid
       start program = "/bin/sh -c '/etc/init.d/Sxxproc_x start'"
       stop  program = "/bin/sh -c '/etc/init.d/Sxxproc_x stop'"
       if 1 restart within 1 cycle then exec "<some error cmd>"
           repeat every 1 cycle
       if not exist for 3 cycles then restart
       else if succeeded 2 times within 2 cycles then exec "<some restore cmd>"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-03-20
      • 1970-01-01
      • 1970-01-01
      • 2020-06-07
      • 1970-01-01
      • 2010-10-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多