Supervisord - 多个项目的环境变量冲突

问题描述 投票:0回答:3

我有两个基于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?

python django virtualenv gunicorn supervisord
3个回答
0
投票

为每个站点配置不同的配置文件。


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.shpb.sh都是这样的: -

while :
    do echo $PYTHONPATH
    sleep 2s
done

然后我跑上监督: -

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


0
投票

如果你正在使用virtualenv,你只需要改变你的PATH,而不是PYTHONPATH,如here

© www.soinside.com 2019 - 2024. All rights reserved.