What is the best way to provide the environment variables defined in /etc/environment
to an upstart service?
I think simply sourcing them with .
in a script section does not work, because the scripts are executed by sh
which would need an additional export
in front of every definition...
I finally got an answer on the
#upstart
IRC channel. At some point, upstart will get proper PAM support and thus read/etc/environment
itself. Until then, the trick is to execute the command with su.su
uses PAM and will set up the proper environment. Example:I tend to use
eval $(cat /etc/environment | sed 's/^/export /')
It takes each line in
/etc/environment
, prependsexport
, and evaluates it:Add this to your script:
where the variables you need are specified in place of the "VAR1" style placeholders.