Python Supervisord-多个项目的环境变量冲突
我有两个网站建立在Django上,它们都使用Python Supervisord-多个项目的环境变量冲突,python,django,virtualenv,gunicorn,supervisord,Python,Django,Virtualenv,Gunicorn,Supervisord,我有两个网站建立在Django上,它们都使用gunicorn管理Supervisor2 supervisord.conf: [program:site1] environment=PYTHONPATH="/home/www/virtualenv/site1/bin/:/home/www/site1/" command=/home/www/virtual/site1/bin/gunicorn wsgi:app -b localhost:1234 directory=/home/www/site1/
gunicorn
管理Supervisor2
supervisord.conf:
[program:site1]
environment=PYTHONPATH="/home/www/virtualenv/site1/bin/:/home/www/site1/"
command=/home/www/virtual/site1/bin/gunicorn wsgi:app -b localhost:1234
directory=/home/www/site1/
...
[program:site2]
environment=PYTHONPATH="/home/www/virtualenv/site2/bin/:/home/www/site2/"
command=/home/www/virtual/site2/bin/gunicorn wsgi:app -b localhost:1235
directory=/home/www/site2/
...
通过这种配置,我注意到site2尝试从site1的设置开始,但失败了,因为它找不到site1所需的包,因为它们没有安装在site2的virtualenv中。
我认为这是因为两个站点之间的PYTHONPATH
混合。
如何正确设置两个站点以仅使用自己的virtualenv?每个站点有不同的配置文件。我使用简单配置进行测试,如下所示:-
[supervisord]
[program:a]
command = /bin/bash pa.sh
environment = PYTHONPATH=/tmp/a
stdout_logfile = /tmp/a.log
[program:b]
command = /bin/bash pb.sh
environment = PYTHONPATH=/tmp/b
stdout_logfile = /tmp/b.log
pa.sh
和pb.sh
看起来都像这样:-
while :
do echo $PYTHONPATH
sleep 2s
done
然后我运行supervisord:-
supervisord -c sp.cfg -n
2013-09-25 00:43:12,942 INFO supervisord started with pid 15362
2013-09-25 00:43:13,945 INFO spawned: 'a' with pid 15365
2013-09-25 00:43:13,948 INFO spawned: 'b' with pid 15366
2013-09-25 00:43:14,967 INFO success: a entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
2013-09-25 00:43:14,968 INFO success: b entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
检查/tmp/a.log
和/tmp/b.log
:-
cat /tmp/a.log
/tmp/a
/tmp/a
/tmp/a
/tmp/a
cat /tmp/b.log
/tmp/b
/tmp/b
/tmp/b
/tmp/b
因此,这两个环境都得到了改善。supervisordversion-3.0如果您使用的是virtualenv,您只需要更改
路径,而不是前面提到的PYTHONPATH