views:

1248

answers:

2

I have an install of django on apache using embedded wsgi. I DON'T have root on the machine.

How can I tell apache to reload the python instance when I deploy new source code?

I tried removing all the .pyc files and it still is running the old code.

+2  A: 

http://code.google.com/p/modwsgi/wiki/ReloadingSourceCode

This article about reloading source code with mod_wsgi goes into how to reload source code, and even how to create a monitor script to automatically reload the daemon when you make source changes. It's really good for setting up a development environment using mod_wsgi.

Marquis Wang
That link seems to recommend `MaxRequestsPerChild 1` which will kill my performance. I was looking for a way to reload it whenever I do a push.
Paul Tarjan
You don't have to use that... check out the next three sections in the article about daemon mode and code change monitoring.
Marquis Wang
Daemon mode is the answer. Two lines in the apache config, and it doesn't cost must performance. thanks
Paul Tarjan
The document actually says about MaxRequestsPerChild that 'using this method is not recommended'. So, although it explains that you can do it, you really should use mod_wsgi daemon mode instead. It definitely isn't being recommended as you suggest.
Graham Dumpleton
+4  A: 

If you are running mod_wsgi in daemon mode with apache, you may not have to restart apache to get it to reload.

I just touch my wsgi file (unix: touch updates the 'saved date' of a file) and apache reloads it on next access/web-hit.

See http://code.google.com/p/modwsgi/wiki/QuickConfigurationGuide

... as long as you can alter the timestamp on the WSGI script.

joej
"touch filename.wsgi" is the correct way to do it, and does not require root or restarting apache. Since I generally only want to do this immediately after checking out new code, I set up an alias to get latest code and touch the wsgi at the same time, e.g.:alias upcrest='cd /home/crest/sites/projects/ourcrestmont; svn up; touch /home/crest/our/ourcrestmont.wsgi'
shacker
Exactly!Good idea with the command alias.
joej
There are quiet a few catch, see http://code.google.com/p/modwsgi/wiki/ReloadingSourceCode#Reloading_In_Embedded_Mode
Wernight