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

I've added the following line to /etc/environment:

FOO_DEPLOYMENT_ENV="vbox"

Upon logging in via SSH, I can echo $FOO_DEPLOYMENT_ENV and, of course, see vbox output to the shell. If I open a Python shell and run os.getenv('FOO_DEPLOYMENT_ENV'), it will return 'vbox', but the same code in my Python application, when run by uWSGI (as the www-data user), it does not see the environment variable.

Clearly, this isn't a problem of uWSGI, and is rather a problem with my understanding of environment variables, or how they're properly set, and the contexts in which they can be retrieved. What am I doing or understanding incorrectly?

share|improve this question
    
Most servers filter out system environments in their startup scripts by design, as a security feature. There is probably some method specific to uWSGI to set environment variables. –  Zoredache Dec 19 '12 at 23:19
    
It's not the server filtering out environment variables--WSGI itself just never loads them. You can set them within the WSGI script itself (which is usually just a stub that sets variables and loads the actual project), but I'm not sure if that's the recommended method, or if it's even suitable to your use case. –  SevenSidedDie Dec 20 '12 at 0:07
add comment

1 Answer

up vote 1 down vote accepted

In short you can't. An environment variable is allowed to exist in a specific shell instance AND can be exported to sub-shells. But in no case can you export environment variables to the a more Parent shell and certainly not outside any inheartence chain of shells.

However, you can store entries in a file as you suggest and then import them manually by the '.' command in the event of SH derivatives or the source command by CSH derivatives.

I personally use tcsh for my interactive shell. If you were using that you could put an alias called cwdcmd that would execute a set of commands between each entered command. I use this facility to put the hostname, username, and current working directory in my command prompts. Using this facility you could put an include directive that would adjust your environment between each command prompt.

share|improve this answer
add comment

Your Answer

 
discard

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.