0

I have two sites build on Django, both of them use gunicorn managed with 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/
...

With this configuration I noticed that site2 tries to start with settings of site1, and fails because it cant find packages that required for site1, because they are not installed in virtualenv of site2. I think that it happens because of PYTHONPATH mixes between two sites. How to properly setup both sites to use only own virtualenv?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Gill Bates
  • 14,330
  • 23
  • 70
  • 138

3 Answers3

0

Have different configuration files for each site.

Marcin
  • 48,559
  • 18
  • 128
  • 201
0

I test with simple config as below:-

[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

Both pa.sh and pb.sh look like this:-

while :
    do echo $PYTHONPATH
    sleep 2s
done

Then I run 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) 

Check /tmp/a.log and /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

So both environment being picked up. Supervisord version - 3.0

k4ml
  • 1,196
  • 12
  • 17
0

If you're using virtualenv, you just need to alter your PATH, not PYTHONPATH, as mentioned here.

Community
  • 1
  • 1
WhyNotHugo
  • 9,423
  • 6
  • 62
  • 70