0

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

4

3 回答 3

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

所以这两个环境都被捡起来了。监督版本 - 3.0

于 2013-09-24T16:47:03.373 回答
0

如果您使用的是 virtualenv,您只需要更改您的PATH, not PYTHONPATH,如此所述。

于 2014-09-09T12:26:16.240 回答
0

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

于 2013-09-24T16:37:29.433 回答