【问题标题】:Monit wait for a file to start a process?监视等待文件启动进程?
【发布时间】:2016-03-29 00:59:19
【问题描述】:

基本上是在文件“product_id”准备好时启动进程“CAD”的监视器。我的配置如下:

check file product_id with path /etc/platform/product_id
  if does not exist then alert

check process cad with pidfile /var/run/cad.pid   
  depends on product_id   
  start = "/bin/sh -c 'cd /home/root/cad/scripts;./run-cad.sh 2>&1 | logger -t CAD'" with timeout 120 seconds   
  stop = "/bin/sh -c 'cd /home/root/cad/scripts;./stop-cad.sh 2>&1 | logger -t CAD'"

我希望“monit”调用“start”,直到文件可用。但似乎它在每个周期都重新启动了进程(停止和启动)。

这里有什么配置错误吗?

感谢任何帮助。

【问题讨论】:

标签: monit


【解决方案1】:

它在每个周期都重新启动的原因是因为product_id 文件还没有准备好。如果检查失败,任何依赖于product_id 的东西都将重新启动。

我建议编写一个脚本来检查 product_id 是否存在,如果存在则启动 CAD。然后,您可以从监视器中的“检查程序”块运行此脚本。

【讨论】:

    【解决方案2】:

    这就是我的做法:

    check program ThisIsMyProgram with path "/home/user/program_check.sh"
            every 30 cycles
            if status == 1 then alert
    

    这将运行 shell 脚本,如果 status = 1 则会出错。

    Shell 脚本:

    #!/bin/bash
    
    FILE=/path/to/file/that/needs/to/exist.json
    PID=$(sudo pidof ThisIsMyProgram)
    
    if [ -s $FILE ]; then
        if [ ! -z "$PID" ];then
            exit 0
        else
            sudo service thisismyprogram start 2>&1 >> /dev/null
            exit 1
        fi
    else
        exit 0
    fi
    

    Shell 脚本检查文件是否存在,如果存在,它将启动进程并保持运行。

    【讨论】:

      猜你喜欢
      • 2013-10-20
      • 1970-01-01
      • 1970-01-01
      • 2011-07-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多