【问题标题】:Monit's second "Does not exist" overrides first oneMonit 的第二个“不存在”覆盖第一个
【发布时间】:2016-10-25 12:28:56
【问题描述】:

我有一个使用 Monit 监控的进程。如果进程由于某种原因而死,我想使用 shell 脚本发送 Slack 通知并重新启动它。这种行为虽然不适用于“不存在”指令。最后一个被执行,前一个被忽略。例如下面的代码:

check process xyz with pidfile /var/run/xyz.pid
  start program = "/etc/init.d/xyz start" with timeout 60 seconds
  stop program = "/etc/init.d/xyz stop"
  if does not exist then restart
  if does not exist then exec "/opt/somescript.sh"

它执行脚本但不重新启动。从文档中也可以看出它的行为方式。任何其他方式来得到这个工作。文档参考(不完全清楚,但类似于实际行为):

If not defined, it defaults to a restart action.
You can override the default action with the following statement:

【问题讨论】:

    标签: monitoring monit


    【解决方案1】:

    我相信 monit 不允许您重复使用相同的语句。您必须在 somescript.sh 中编写脚本以重新启动进程。

    【讨论】:

      【解决方案2】:

      我的猜测是,根据文档,默认操作已经是重新启动进程,而您正在使用 exec 操作覆盖它

      更简洁的方法是在 somescript.sh 中添加重启脚本。

      如果你不想这样做,你也可以将这两个动作合二为一,像这样:

      if does not exist then exec "/etc/init.d/xyz restart && /opt/somescript.sh"
      

      【讨论】:

      • 抱歉,这只是我在输入问题时的拼写错误,现在更正
      • 哦,我明白了。我更新了答案,可能最好将重启和脚本放入 1 个动作中。
      • 出于某种奇怪的原因,即使我在 exec 中调用两个命令,用 && 分隔 - 它只调用第一个。我通过更改位置对此进行了测试,但始终只调用一个命令!
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-06-05
      • 2021-04-12
      • 1970-01-01
      • 1970-01-01
      • 2019-04-26
      • 1970-01-01
      • 2015-09-19
      相关资源
      最近更新 更多