How to set environment variables in Supervisor service

PythonSupervisord

Python Problem Overview


How do you export environment variables in the command executed by Supervisor? I first tried:

command="export SITE=domain1; python manage.py command"

but Supervisor reports "can't find command".

So then I tried:

command=/bin/bash -c "export SITE=domain1; python manage.py command"

and the command runs, but this seems to interfere with the daemonization since when I stop the Supervisor daemon, all the other daemons it's running aren't stopped.

Python Solutions


Solution 1 - Python

To add a single environment variable, You can do something like this.

[program:django]
environment=SITE=domain1
command = python manage.py command

But, if you want to export multiple environment variables, you need to separate them by comma.

[program:django]
environment = 
    SITE=domain1,
    DJANGO_SETTINGS_MODULE=foo.settings.local,
    DB_USER=foo,
    DB_PASS=bar
command = python manage.py command

Solution 2 - Python

Just do it separately:

environment=SITE=domain1
command=python manage.py command

Refer to http://supervisord.org/subprocess.html#subprocess-environment for more info.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionCerinView Question on Stackoverflow
Solution 1 - PythonPandikunta Anand ReddyView Answer on Stackoverflow
Solution 2 - Pythonneko_uaView Answer on Stackoverflow