monit call exec on process recovery

时间:2016-12-19 10:31:35

标签: monit

我想做的是以下内容:

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

对于通过电子邮件发出的警报,恢复时默认情况下会发送通知。但是对于exec方法,我找不到一种方法来完成这项工作。如果我在monitrc中尝试这个:

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>"

这导致&#34; 语法错误&#39;否则&#39; &#34;。如果我删除else行,则按预期调用error命令。显然,“其他”&#39;不能用于重启测试。但是如何添加执行命令是程序启动成功还是恢复?

1 个答案:

答案 0 :(得分:0)

由于这个主题的答案,我找到了一个解决方案:

get monit to alert first and restart later

如果不存在...... ”与相应的“ else ”为我提供了报告恢复的技巧。错误报告是独立的。我的monitrc代码现在:

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>"