Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

How does one go about getting a new environment variable picked up system-wide without restarting the server?

As its an Ubuntu 11.x server, I'm using Upstart to start/restart processes.

I added a new environment variable to /etc/environment that needs to be picked up by one of my app's processes.

If I start the process directly from my shell, the variable is being picked up and all is fine (I've already sourced /etc/environment for my session). However, when I start/restart the process using its Upstart service name, the variable is not being seen.

 sudo start app-name

I'm pretty sure that if I restarted the server the new variable will get picked up, however I would like to try to avoid that. I have some other live processes running on it that I'd like to avoid interrupting if at all possible.

share|improve this question

2 Answers 2

Put the env stanza in your upstart job description file.


env PIDFILE=/var/run/myprocess.pid

Or whatever. It's all in the documentation.

share|improve this answer
Thanks, I can totally make that work. I'd like to go further and make it global and permanent though. I'm setting a variable that multiple processes can use to determine if they're in a development or production environment. The conf file will work for now because I develop on a Mac, but I eventually will have an integration environment running Ubuntu and each server will run multiple separate app processes. It would be convenient for them all not to rely on the confs. –  Geuis Dec 17 '11 at 11:09
What? You wanna use Upstart. Good. You need to specify things in the Upstart's configuration so that it knows how to start the processes. It's either that, or you make a wrapper script that sets and exports environment variables (messy) Or modify the default bash profile, so they're always set and exported (Insanely Messy). –  Tom O'Connor Dec 17 '11 at 11:12
The right way to do this is to use something like Puppet to manage your different environments, and then Puppet can manage the different configuration files, across many servers, without fuss. –  Tom O'Connor Dec 17 '11 at 11:13
Tom, I'm running into an odd problem. Using env, I can't set any custom environment variables. If I set system defined vars, they are being read by the app. But my own aren't. For example, I set without quotes in the conf, "env DISPLAY=foo" and DISPLAY is picked up with a value of foo. But if I set "env TESTENV=foo" the variable TESTENV isn't even detected. –  Geuis Dec 17 '11 at 11:53
I'll give rc.local a try after a bit of sleep. Thanks for the setgid tips. I've also been hesitant about sudo but that's what most of the examples I've seen do and it works. For my existing apps, its been working pretty reliably for a while now but I'm going to look into your link and see how it could be done more securely. Really appreciate your help tonight and hopefully I can figure out the rest. –  Geuis Dec 17 '11 at 13:50

I had the same problem. My startup script worked fine from the command line, but not from upstart script.

I simply had to source my . /home/username/.bashrc in my upstart script to get it working with all the correct environment variables.


  cd /home/me
  . /home/me/.bashrc

end script
share|improve this answer
This does not work for me (Ubuntu Server 14.04.1). I get no error when sourcing /home/<user>/.bashrc inside the Upstart script, but the env vars don't stick around for the next command (the app/service being started). –  odigity Jan 12 at 0:29

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.