supervisord environment variables setting up application

2024/10/14 1:17:45

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.

Answer

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.

https://en.xdnf.cn/q/69470.html

Related Q&A

Updating gui items withing the process

I am trying to make a GUI for my app and ran into a problem: using PySimpleGUI I have to define layout at first and only then display the whole window. Right now the code is like this:import PySimpleGU…

UnicodeDecodeError with Djangos request.FILES

I have the following code in the view call..def view(request):body = u"" for filename, f in request.FILES.items():body = body + Filename: + filename + \n + f.read() + \nOn some cases I getU…

bifurcation diagram with python

Im a beginner and I dont speak english very well so sorry about that. Id like to draw the bifurcation diagram of the sequence : x(n+1)=ux(n)(1-x(n)) with x(0)=0.7 and u between 0.7 and 4.I am supposed …

How do I use nordvpn servers as python requests proxies

Dont ask how, but I parsed the server endpoints of over 5000 nordvpn servers. They usually are something like ar15.nordvpn.com for example. Im trying to use nordvpn servers as request proxies. I know i…

Python Proxy Settings

I was using the wikipedia module in which you can get the information that is present about that topic on wikipedia. When I run the code it is unable to connect because of proxy. When I connected PC to…

Docker - Run Container from Inside Container

I have two applications:a Python console script that does a short(ish) task and exits a Flask "frontend" for starting the console app by passing it command line argumentsCurrently, the Flask …

Way to run Maven from Python script?

(I am using Windows.)I am trying to run maven from a python script. I have this:import subprocessmvn="C:\\_home\\apache-maven-2.2.1\\bin\\mvn.bat --version" p = subprocess.Popen(mvn, shell=Tr…

Why does testing `NaN == NaN` not work for dropping from a pandas dataFrame?

Please explain how NaNs are treated in pandas because the following logic seems "broken" to me, I tried various ways (shown below) to drop the empty values.My dataframe, which I load from a C…

Python dynamic import methods from file [duplicate]

This question already has answers here:How can I import a module dynamically given its name as string?(10 answers)How can I import a module dynamically given the full path?(37 answers)Closed last yea…

Python list does not shuffle in a loop

Im trying to create an randomized list of keys by iterating:import randomkeys = [1, 2, 3, 4, 5] random.shuffle(keys) print keysThis works perfect. However, if I put it in a loop and capture the output:…