Question: We have certain sysadmin settings that we expose to superusers of our django webapp. Things like the domain name (uses contrib.sites) and single sign-on configuration. Some of these settings are cached by the system, sometimes because we want to avoid an extra DB hit in the middleware on every request if we can help it, sometimes because it's contrib.sites, which has its own caching. So when the settings get changed, the changes don't take effect until the app is reloaded.

We want the app to restart itself when these changes are made, so that our clients don't need to pester us to do the restart for them.

Our webapp is running on apache via mod\_wsgi, so we should be able to do this just by touching the wsgi file for the app whenever one of these settings is changed, but it feels a little weird to do that, and I'm worried there's some more graceful convention we should be following.

Is there a right way to apply updates that are cached and require the app to reload? Invalidating the caches for these things will be pretty hairy, so I think I'd avoid that unless the app restart thing has serious drawbacks.

Answer: 
For mod\_wsgi read:

* <http://code.google.com/p/modwsgi/wiki/ReloadingSourceCode>

Some other WSGI servers have similar options, but options in other WSGI servers are usually more limited.
It depends on your setup:

* If you are using wsgi on a single server you could touch the wsgi file to let apache restart every instance of the app
* If you are using gunicorn you probably use supervisord to controll it. Then a supervisorctl restart APPNAME would be the solution
* If you scale your app on multiple servers you have to ensure that every server restarts their instances. There are several ways to achieve this:
	+ use the same filesystem if you are using mod\_wsgi then a touch would count for every server
	+ log in to the other servers using ssh and make them restart your app

I am sure there are more ways to restart your app but it highly depends on your setup and whether or not you have to restart all instances or only one.