有没有办法通过 Monit 配置传递环境变量

Is there a way to pass Environment variables through a Monit config

我有一个脚本需要由 Monit 保持活动状态。如何将我的环境变量传递给这个脚本?类似于:

check host steve with address localhost
        group nn
        ENV = "DBHOST=localhost" #this doesn't work...
        start program = "/home/steve.sh start"
        start program = "/home/steve.sh restart"
        if failed port 80 protocol http for 2 cycles then restart

无法将 ENV 传递给带有 monit 的脚本。

完成此操作的最简单方法可能是使用参数:

添加一个桥脚本 /home/monit_steve.sh:

#!/bin/bash
export DBHOST=""
/home/steve.sh ""
exit $?

然后更新您的 monitrc 以匹配(您目前有 2x start program...):

check host steve with address localhost
  group nn
  start program = "/home/monit_steve.sh localhost start"
  restart program = "/home/monit_steve.sh localhost restart"
  if failed port 80 protocol http for 2 cycles then restart