I'm running an application from supervisord and I have to set up an environment for it. There are about 30 environment variables that need to be set. I've tried putting all on one big
environment=
line and that doesn't seem to work. I've also tried multiple enviroment= lines, and that doesn't seem to work either. I've also tried both with and without ' around the env value.
What's the best way to set up my environment such that it remains intact under supervisord control? Should I be calling my actual program (tornado, fwiw) from a shell script with the environment preloaded there? Ideally, I'd like to put all of the enviroment variables into an include file and load them with supervisor, but I'm open to doing it another way.
UPDATE:
Here is what I'm using in the conf file:
environment=
PYTHONPATH=/srv/obsf/current/:$PYTHONPATH,
PYTHON_EGG_CACHE=/srv/obfs/current/.python-eggs,
OBFS_API_ENVIRONMENT_STAGE=test,
This goes on for about 30 lines, with a lot of environment variables. When I execute the program, it crashes immediately complaining that the environment variable OBFS_API_ENVRIONMENT_STAGE is not set.
The relevant documentation section
explains that you need to list the variables as comma-separated key/value pairs:
environment
A list of key/value pairs in the form KEY=val,KEY2=val2 that will be placed in the supervisord process’ environment (and as a result in all of its child process’ environments). This option can include the value %(here)s, which expands to the directory in which the supervisord configuration file was found. Note that subprocesses will inherit the environment variables of the shell used to start supervisord except for the ones overridden here and within the program’s environment configuration stanza.
The example for this section
also uses commas:
environment = KEY1=value1,KEY2=value2
Internally this is parsed into a dict
using the python shlex
lexer, so it'll deal with quoting properly. It'll also strip whitespace, so to make things more readable, you could divide things over multiple lines:
environment =
KEY1="Some longer value containing whitespace",
KEY2=value2-on-a-new-line,
Note that a trailing comma is optional; it won't make a difference in the output.
Missing a comma after KEY1 however could lead to weird values (the above example, minus the comma after whitespace"
would give you {'KEY1': 'Some longer value containing whitespace', '=': ','}
as the environment dict) as the equals sign requirement isn't rigorously checked. I've submitted a pull request to remedy that.
As it turns out, the trailing comma is an issue. I quoted all the env strings and removed the trailing comma. All works now.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With