Have upstart read environment from /etc/environment for a service

Solution 1:

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:

script 
    exec su root -c /usr/sbin/job_needing_envs
end script

Solution 2:

I tend to use eval $(cat /etc/environment | sed 's/^/export /')

It takes each line in /etc/environment, prepends export, and evaluates it:

script
exec /bin/bash <<'EOT'
  eval $(cat /etc/environment | sed 's/^/export /')
  do_what_you_need_to
EOT
end script

Solution 3:

Add this to your script:

. /etc/environment
export VAR1 VAR2 VAR3

where the variables you need are specified in place of the "VAR1" style placeholders.