1

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?

orokusaki
  • 2,763
  • 4
  • 32
  • 43
  • 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 00:07

1 Answers1

1

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.

mdpc
  • 11,856
  • 28
  • 53
  • 67