Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Restarting a Django application running on Apache + mod_python

I'm running a Django app on Apache + mod_python. When I make some changes to the code, sometimes they have effect immediately, other times they don't, until I restart Apache. However I don't really want to do that since it's a production server running other stuff too. Is there some other way to force that?

Just to make it clear, since I see some people get it wrong, I'm talking about a production environment. For development I'm using Django's development server, of course.

like image 688
ibz Avatar asked Jul 03 '09 07:07

ibz


3 Answers

If possible, you should switch to mod_wsgi. This is now the recommended way to serve Django anyway, and is much more efficient in terms of memory and server resources.

In mod_wsgi, each site has a .wsgi file associated with it. To restart a site, just touch the relevant file, and only that code will be reloaded.

like image 57
Daniel Roseman Avatar answered Nov 09 '22 08:11

Daniel Roseman


As others have suggested, use mod_wsgi instead. To get the ability for automatic reloading, through touching the WSGI script file, or through a monitor that looks for code changes, you must be using daemon mode on UNIX. A slight of hand can be used to achieve same on Windows when using embedded mode. All the details can be found in:

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

like image 30
Graham Dumpleton Avatar answered Nov 09 '22 07:11

Graham Dumpleton


You can reduce number of connections to 1 by setting "MaxRequestsPerChild 1" in your httpd.conf file. But do it only on test server, not production.

or

If you don't want to kill existing connections and still restart apache you can restart it "gracefully" by performing "apache2ctl gracefully" - all existing connections will be allowed to complete.

like image 1
tefozi Avatar answered Nov 09 '22 08:11

tefozi