我有两个基于Django的网站,他们都使用gunicorn
管理supervisor 2
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?
答案 0 :(得分:0)
为每个站点提供不同的配置文件。
答案 1 :(得分:0)
我用简单的配置测试如下: -
[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
所以两个环境都被捡起来了。 Supervisord版本 - 3.0
答案 2 :(得分:0)
如果您使用的是virtualenv,则只需更改PATH
,而不是PYTHONPATH
,如上所述here。