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

link|improve this question
feedback

3 Answers

up vote 0 down vote accepted

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.

link|improve this answer
Would you check my updated question? Thanks! – Mark Nov 11 '09 at 13:11
Are you deploying projects with Puppet or another mechanism? I would say it is best done in the same breath as deployment, rather than a separate process. – Dan Carley Nov 11 '09 at 13:21
I guess there puppet is the only choice I have. I already use it for deployment. Thanks! – Mark Nov 11 '09 at 15:27
Not your only choice, but probably your efficient. Just notify an exec { .. command => "touch ..", refreshonly => true } at the time your project resource changes. – Dan Carley Nov 11 '09 at 15:52
feedback

There is no difference between (2) and (3) in respect of how existing requests are effected. Sending a kill SIGINT does not just exit the process but triggers the same sort of orderly shutdown as (2) does. In fact, (2) internally just sends a SIGINT to itself. The important thing is identifying the processes which need SIGINT sent to them. For this you should use 'display-name' option to WSGIDaemonProcess so they are named in 'ps' output and easier to identify.

link|improve this answer
feedback

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

I guess this resolves the problem of how to trigger mod_wsgi to reload the scripts in a very elegant way. For the distribution of this action among several hosts at the same time, I recommend using an utility like pssh (parallel ssh). Its configuration should not be a problem.

link|improve this answer
Would you check my updated question? Thanks! – Mark Nov 11 '09 at 13:12
In this case I have nothing to add to the conversation. Sorry. – Born To Ride Nov 11 '09 at 15:04
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.