10

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.

Paul Tarjan
  • 48,968
  • 59
  • 172
  • 213

2 Answers2

14

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
  • 1,130
  • 6
  • 9
  • 3
    "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 Jul 02 '09 at 15:40
  • There are quiet a few catch, see http://code.google.com/p/modwsgi/wiki/ReloadingSourceCode#Reloading_In_Embedded_Mode – Wernight Aug 01 '10 at 21:35
5

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
  • 10,878
  • 5
  • 30
  • 25
  • 1
    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 Jul 01 '09 at 20:08
  • 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 Jul 01 '09 at 20:21
  • Daemon mode is the answer. Two lines in the apache config, and it doesn't cost must performance. thanks – Paul Tarjan Jul 01 '09 at 21:46
  • 4
    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 Jul 02 '09 at 00:55