servermon/servermon — pull request #53 by rowanthorpe (2014-04-13 22:24:09+00:00)
Title: Updates to Apache wsgi file

After discussing maintenance mode in issue #47 I found a way to make switching to and from it as easy as setting one variable in the wsgi file and reloading, while allowing for changes in the maintenance page without restarts, and adding effectively zero overhead to non-maintenance mode ("actually zero" for requests, "effectively zero" for app reloads). Of course if really deep maintenance is being done and wsgi/maintenance-file locations or contents can't be guaranteed then it would need to be done on the server-level anyway, which this won't interfere with, but I expect for 90% of cases (i.e. upgrading) this would make things much easier and less error-prone. If you still aren't convinced then I could instead either add this code as commented alternate code below the existing code, or even in a separate file like `django-alt.wsgi.dist`. If so let me know and I will change the PR. BTW: is there a reason it is in an "apache" directory? The wsgi code seems to be entirely server-agnostic, and the naming might confuse/deter people who are scanning the install info in a hurry...

The below changes were made:

* check if _app_path is already in sys.path before appending it

* switch to maintenance mode when Apache is reloaded and
_maint_mode == True

* abstract _app_path and _maint_mode to top of code and label it for
editing

* label _maint_file at top of maintenance-specific code for editing (if a
custom page is being used)

* stat maintenance page to pick up changes without server-reloading (but
don't use inotify/etc because doing it portably without sourcing Django
libs adds too much complexity to be worth it for one static page)

* in non-maintenance mode there is a _tiny_ added cost of one
var-assignment and one if-branch during server reload/restart, but
actual requests have no extra overhead (the "application" function is
unchanged)

* in maintenance mode, for speed-reasons, global vars are used instead of
arg-passing

* update copyright year, and s/ISC/THE AUTHOR/ in copyright notice