Monit“检查程序”并根据退出码重新启动

当我使用check processmonit会启动我在start program下定义的start program然后monit会在start program停止时重新启动它。

但是,当我使用check program monit不会自动启动它。 如果程序正在运行,并由于某种原因停止与非0的退出代码monit将不会重新启动它(见我的configuration下面)。

我真的不知道如何根据我的退出代码正确启动和重新启动程序。

我的configuration文件如下所示:

 set logfile /tmp/monit.log set daemon 1 check program MyProgram with path “/monit/MyProgram.py” and with timeout 3600 seconds every 1 cycles start program = “/monit/MyProgram.py” with timeout 3600 seconds if status > 200 then restart if status < 201 then stop if 2 restart 5 cycles then exec “/monit/custom_script.sh” if 2 restart 5 cycles then stop 

我已经试过像这样开始监视

  • monit -c monitrc -vv
  • monit -c monitrc start all -vv
  • monit -c monitrc start MyProgram -vv