Reputation: 1145
My project is based on Django, Nginx, Gunicorn and Supervisor in a Virtual env.
I export environmental variables at the end of the ./bin/activate
script. Whenever I source
the activate file, it exports environmental variables. It's pretty cool...
My issue comes when I start the Supervisor script. It seems that the ./bin/activate
isn't sourced as Django can't get vars such as SECRET_KEY.
I heard people using a post-activate script which isn't present in my virtualenv bin dir. Am I missing something important? Why Supervisor doesn't source the ./bin/activate
script?
Here is my supervisor conf:
command=/opt/.virtualenvs/plcweb/bin/gunicorn plcweb.config.wsgi -c /opt/plcweb/gunicorn.conf.py
directory=/opt/plcweb/project
user=bastien
autostart=true
autorestart=true
redirect_stderr=True
stdout_logfile=/opt/plcweb/gunicorn.log
stderr_logfile=/opt/plcweb/gunicorn.log
Upvotes: 1
Views: 1230
Reputation: 1145
As explained here, you have a very simple solution with the environment
directive. So to export DJANGO_SETTINGS_MODULE, supervisor conf file should be as following:
command=/opt/.virtualenvs/plcweb/bin/gunicorn plcweb.config.wsgi -c /opt/plcweb/gunicorn.conf.py
environment=DJANGO_SETTINGS_MODULE=my_project.settings.production
directory=/opt/plcweb/project
user=bastien
Upvotes: 1