I need to export a variable FOO=stringhere so that system processes could use it. And the place I would like to do this, is Upstart job.

Unfortunately, I tried as per Upstart manual to do env FOO=stringhere http://upstart.ubuntu.com/cookbook/#environment-variables

But after the system is booted, echo $FOO returns nothing.

Am I trying to do something impossible, or are there any gotchas I should know?


3 Answers 3


As the page you refer to says,

Upstart allows you to set environment variables which will be accessible to the jobs whose job configuration files they are defined in.

The indicates that the variables are set in the environment used by the system daemons at startup. The user environment is configured separately once you log in.

If you want to check whether the daemon knows about the variable you set, you can test that by temporarily modifying its startup script and adding something like logger "=============== The variable FOO is set to $FOO =====================". You should then see the information logged during boot-up (look in /var/log/messages for example).

  • Any ideas on how I could work around this feature?
    – Coder
    Commented Sep 15, 2011 at 14:41
  • What do you mean by feature here? What is your goal - knowing if the variable is used at system startup (see my edit for that) or having the variable exported to all your users' shell sessions? Commented Sep 15, 2011 at 14:46
  • Yes, so that every user on the system could type echo $FOO and get the stringhere.
    – Coder
    Commented Sep 15, 2011 at 14:50
  • You answered "yes" to which one of the two @rozcietrzewiacz's question?
    – andcoz
    Commented Sep 15, 2011 at 14:58
  • 1
    If you really just want to have a "public" variable visible to all users, then a system startup job is not the place to set it. But your question points at a problem of setting a variable which, as you wrote, system processes could use. This is a different issue (also useful). So please decide to either modify the question or ask a separate one. Commented Sep 15, 2011 at 16:36

In your example that variable could be used in the same file.

Note from upstart cookbook.

Note that a Job Configuration File does not have access to a user's environment variables, not even the superuser. This is not possible since all job processes created are children of init which does not have a user's environment.

Further explanation from upstart cookbook.

Lets say you write env TESTING=123 in your *.conf file, then you can use this variable in your script block below (the one you used)

  # prints "TESTING='123'" to system log
  logger -t $0 "TESTING='$TESTING'"
end script

Or a bit more sophisticated approach would let you use you variable in jobs that 'listen' to your job:

# /etc/init/A.conf
start on wibble
export foo

# /etc/init/B.conf
start on A
  logger "value of foo is '$foo'"
end script

What you want to accomplish is better suited to /etc/profile which is source'ed by login shells.

export foo="String here"

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .