57

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.

2 Answers 2

109

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
1
  • 1
    How can we do this automatically? Let's say we need to set the environment variable when the server is starting up. so how can we set this to happen with a startup script? Nov 11, 2020 at 9:54
20

Just do it separately:

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

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

1
  • Environment Variables PORT=8000 command=uwsgi --ini uwsgi.ini --http :<PORT> How do I use it on the command line?
    – josue
    Nov 23, 2020 at 19:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.