How to use virtualenvwrapper in Supervisor?

家住魔仙堡 提交于 2019-11-27 02:36:41

问题


When I was developing and testing my project, I used to use virtualenvwrapper to manage the environment and run it:

workon myproject
python myproject.py

Of course, once I was in the right virtualenv, I was using the right version of Python, and other corresponding libraries for running my project.

Now, I want to use Supervisord to manage the same project as it is ready for deployment. The question is what is the proper way to tell Supervisord to activate the right virtualenv before executing the script? Do I need to write a separate bash script that does this, and call that script in the command field of Supervisord config file?


回答1:


One way to use your virtualenv from the command line is to use the python executable located inside of your virtualenv.

for me i have my virtual envs in .virtualenvs directory. For example

/home/ubuntu/.virtualenvs/yourenv/bin/python

no need to workon

for a supervisor.conf managing a tornado app i do:

command=/home/ubuntu/.virtualenvs/myapp/bin/python /usr/share/nginx/www/myapp/application.py --port=%(process_num)s



回答2:


Add your virtualenv/bin path to your supervisord.conf's environment:

[program:myproj-uwsgi]
process_name=myproj-uwsgi
command=/home/myuser/.virtualenvs/myproj/bin/uwsgi
    --chdir /home/myuser/projects/myproj
    -w myproj:app
environment=PATH="/home/myuser/.virtualenvs/myproj/bin:%(ENV_PATH)s"
user=myuser
group=myuser
killasgroup=true
startsecs=5
stopwaitsecs=10



回答3:


First, run

$ workon myproject
$ dirname `which python`
/home/username/.virtualenvs/myproject/bin

Add the following

environment=PATH="/home/username/.virtualenvs/myproject/bin"

to the related supervisord.conf under [program:blabla] section.



来源:https://stackoverflow.com/questions/15202760/how-to-use-virtualenvwrapper-in-supervisor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!