首页 > 解决方案 > 有没有办法通过 Monit 配置传递环境变量

问题描述

我有一个脚本需要 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

标签: monit

解决方案


无法ENV使用 monit 传递给脚本。

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

添加桥接脚本 /home/monit_steve.sh

#!/bin/bash
export DBHOST="$1"
/home/steve.sh "$2"
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

推荐阅读