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
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