monit call exec 进程恢复
monit call exec on process recovery
我想做的是:
- 如果 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>"
这会导致“语法错误 'else'”。如果我删除 else 行,则会按预期调用错误命令。显然,'else' 不能用于 restarts 测试。但是如何添加执行命令是程序启动成功还是恢复?
由于对这个主题的回答,我找到了解决方案:
get monit to alert first and restart later
“if not exist for ...”和相应的“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>"
我想做的是:
- 如果 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>"
这会导致“语法错误 'else'”。如果我删除 else 行,则会按预期调用错误命令。显然,'else' 不能用于 restarts 测试。但是如何添加执行命令是程序启动成功还是恢复?
由于对这个主题的回答,我找到了解决方案:
get monit to alert first and restart later
“if not exist for ...”和相应的“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>"