Steve Northup
Steve Northup

Reputation: 13

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

I have a script that needs to be kept alive by Monit. How can I pass my environment variables to this script? Something like:

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

Upvotes: 1

Views: 1962

Answers (2)

Rade Radenkovic
Rade Radenkovic

Reputation: 1

I know you can use $HOST for this purpose but looks like there are not others available.

Upvotes: 0

boppy
boppy

Reputation: 1908

It's not possible to pass ENV to the script with monit.

The easiest way to get this done might be using parameters:

Add a bridge script /home/monit_steve.sh:

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

Then update your monitrc to match (you currently have 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

Upvotes: 1

Related Questions