supervisord + virtualenv problem

332 views
Skip to first unread message

iain duncan

unread,
Jul 24, 2008, 11:24:54 PM7/24/08
to turbogears
I folks, maybe someone will have a clue for me. I have a bash script in
my tg project directory that sources in the virtual env and then calls
the python start script

source /home/projectuser/project_ve/bin/activate

and then calls start-myproject.py


This seems to work fine, I can cd to /etc, and then call the script
directly as root:

/home/projectuser/project_ve/project/start_project

And the app starts up fine.

But when I add the same command to my supervisord.conf file, it won't
stay running and just exits. In both cases I am running as root. Anyone
know what I might have missed that would make the start up script exit
early?

Thanks
Iain

Diez B. Roggisch

unread,
Jul 25, 2008, 4:28:36 AM7/25/08
to turbo...@googlegroups.com
iain duncan schrieb:

Most probably the supervisord cleans the environment bevore inoking the
script.

Instead of sourcing, you should be able to simply use the VE python
interpreter directly. I had no troubles doing that.

Diez

Christopher Arndt

unread,
Jul 26, 2008, 12:43:32 PM7/26/08
to turbo...@googlegroups.com
iain duncan schrieb:

> I have a bash script in
> my tg project directory that sources in the virtual env and then calls
> the python start script and then calls start-myproject.py

>
> But when I add the same command to my supervisord.conf file, it won't
> stay running and just exits.

This had me puzzled a while ago too. At some point (don't know which
version exactly), supervisor started to clear the ebvironment for the
processes it starts. So you have to set the USER, LOGNAME and HOME
environment variables explicitely for the user under which your TG app
runs. Here's a snippet from one of my supervisor configurations:

[program:pybook_trac]
command=/home/pybook/bin/start-trac /home/pybook/trac/pybook
autostart=true
autorestart=true
user=pybook
startsecs=5
startretries=3
stopsignal=TERM
stopwaitsecs=10
log_stdout=true
log_stderr=true
logfile=/home/pybook/var/log/trac-supervisor.log
logfile_maxbytes=10MB
logfile_backups=10
environment=HOME=/home/pybook,USER=pybook,LOGNAME=pybook


HTH, Chris

iain duncan

unread,
Jul 26, 2008, 10:14:41 PM7/26/08
to turbo...@googlegroups.com

Thanks Chris, I'll try that out. Is the above for a setup running out of
a virtual env?

Iain


Christopher Arndt

unread,
Jul 27, 2008, 6:12:34 AM7/27/08
to turbo...@googlegroups.com
iain duncan schrieb:

> Thanks Chris, I'll try that out. Is the above for a setup running out of
> a virtual env?

Yes, the start script sources the "activate" script or runs the webapp
through the interpreter in $VIRTUAL_ENV/bin/python.

Chris

Jason Chu

unread,
Jul 30, 2008, 5:15:36 PM7/30/08
to TurboGears
I actually went one step further and wrote a script that can execute
any command I want inside the virtualenv environment. It's very
simple:

#!/bin/bash

source /path/to/activate
exec $*

Replace /path/to with your virtualenv path.

From there your script will execute the rest of the arguments as if
they were executed within the virtualenv.

Jason

Christopher Arndt

unread,
Jul 31, 2008, 3:25:37 AM7/31/08
to turbo...@googlegroups.com
Jason Chu schrieb:

> I actually went one step further and wrote a script that can execute
> any command I want inside the virtualenv environment. It's very
> simple:
>
> #!/bin/bash
>
> source /path/to/activate
> exec $*

I'd replace the last line with:

exec "$@"

This will handle arguments with spaces in them correctly.

Chris

Reply all
Reply to author
Forward
0 new messages