Supervising virtualenv django app via supervisor

26,170

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"

...

Share:
26,170
Oleiade
Author by

Oleiade

I'm a software hater therefore I try to fix it. Move fast, break things, and let me fix them up.

Updated on July 09, 2022

Comments

  • Oleiade
    Oleiade almost 2 years

    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?

  • Oleiade
    Oleiade almost 13 years
    Seems to work :) had read something about envs management but didn't found how to apply it. Thank you, really!
  • Lokesh Meher
    Lokesh Meher about 7 years
    @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/sb‌​in:/usr/local/bin:/u‌​sr/sbin:/usr/bin:/sb‌​in:/bin:/usr/games:/‌​usr/local/games:/sna‌​p/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)?
  • Michał Modzelewski
    Michał Modzelewski about 7 years
    @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.