48

I'm trying to use supervisor in order to manage my django project running gunicorn inside a virtualenv. My conf file looks like this:

[program:diasporamas]
command=/var/www/django/bin/gunicorn_django
directory=/var/www/django/django_test
process_name=%(program_name)s
user=www-data
autostart=false
stdout_logfile=/var/log/gunicorn_diasporamas.log
stdout_logfile_maxbytes=1MB
stdout_logfile_backups=2
stderr_logfile=/var/log/gunicorn_diasporamas_errors.log
stderr_logfile_maxbytes=1MB
stderr_logfile_backups=2enter code here

The problem is, I need supervisor to launch the command after it has run 'source bin/activate' in my virtualenv. I've been hanging around google trying to find an answer but didn't find anything.

Note: I don't want to use virtualenvwrapper

Any help please?

user545424
  • 15,713
  • 11
  • 56
  • 70
Oleiade
  • 6,156
  • 4
  • 30
  • 42

1 Answers1

83

The documentation for the virtualenv activate script says that it only modifies the PATH environment variable, in which case you can do:

[program:diasporamas]
command=/var/www/django/bin/gunicorn_django
directory=/var/www/django/django_test
environment=PATH="/var/www/django/bin"
...

Since version 3.2 you can use variable expansion to preserve the existing PATH too:

[program:diasporamas]
command=/var/www/django/bin/gunicorn_django
directory=/var/www/django/django_test
environment=PATH="/var/www/django/bin:%(ENV_PATH)s"

...

Michał Modzelewski
  • 1,320
  • 10
  • 8
  • Seems to work :) had read something about envs management but didn't found how to apply it. Thank you, really! – Oleiade Jul 01 '11 at 08:44
  • @serge-s @michał-modzelewski But doesn't this overwrite the `PATH` environment variable? If that's the case, won't that affect the search path for other binaries not found in that directory. For, e.g., in Ubuntu Linux, the `PATH` is `/home/user_name/bin:/home/user_name/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin`. If some binary is not found in the overwritten PATH, it should be searched in the directories specified in the original PATH. Is there a way to append to the path in supervisor config (e.g. using string formatting)? – Lokesh Meher Feb 15 '17 at 09:24
  • @LokeshMeher This answer is pretty old. Since then supervisor has added an option to use environment variables in the configuration. I've updated the answer with a version that includes the original PATH. – Michał Modzelewski Feb 16 '17 at 12:06