I'm trying to use the variables defined in /etc/environment in an upstart script.
I'm able to export the variable to the child process but for some reason I not able to use them in the upstart script stanza itself.
This works:
script
. /etc/environment
export NODE_ENV
# node is able to read the NODE_ENV, wonderful!
/usr/local/bin/node /path/to/app/app.js
end script
But if I try to introduce some conditional logic within the stanza then it will fail:
script
. /etc/environment
export NODE_ENV
# ${NODE_ENV} is not set inside the stanza
if [[ ${NODE_ENV} = 'production' ]]; then
# this will never run
/usr/local/bin/node /path/to/app/app.js
fi
end script
Any ideas how I can access variables from sourced files inside the stanzas? I really don't want to have to hardcode this stuff!
Best Answer
The problem is your use of "[[". Upstart runs all scripts via /bin/sh. See:
If you look at the jobs log, you should see a (shell) error there:
sudo cat /var/log/upstart/your-job.log