Python – Reloading mod_wsgi processes safely in production

apache-2.2djangomod-wsgipython

Is there a way to safely restart mod_wsgi processes on demand, possibly running on multiple machines? I'm serving a django app with mod_wsgi in daemon mode with apache:

WSGIDaemonProcess myapp user=user group=user processes=30 threads=1
WSGIProcessGroup myapp

I read the suggestions in the mod_wsgi documentation but none of the suggested solutions works for me:

  1. Running a monitoring script is not recommended in a production system.
  2. Sending kill signals is not safe in my case. I want to avoid interrupting running requests. The reload must not bring the service down. Slowing down is fine.
  3. Touching the mod_wsgi configuration file does the trick safely, but how to do it on multiple machines?

Ideally we should be able to restart the processes with one action. Any suggestions?

Note: I have to run multiple processes with one thread. My application is not thread safe.


Edit, I can do it from Puppet if that is the only option I have. but I prefer if there a way to do it from a special protected view. I think this is trivial to do on one machine but not multiple ones


Thanks a lot

Best Answer

Touching the mod_wsgi configuration file does the trick safely, but how to do it on multiple machines?

This would be solved by using a shared codebase such as from an NFS mount.

Alternatively it should be part of your version control / deployment process.

  • Do you use version control currently?

    If so, create a process that ensures the file is updated. You could automate it with a post-commit hook for example.

  • How do you deploy your code?

    Consider using something like Capistrano or Puppet and include an action in your deployment recipe to update that file.