How to set environment variables in Supervisor service

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.


Solution 1:

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:

Just do it separately:

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

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