tags:

views:

173

answers:

1

I run all my Django sites as SCGI daemons. I won't get into the fundamentals of why I do this but this means that when a site is running, there is a set of processes running from the following command:

/websites/website-name/manage.py runfcgi method=threaded host=127.0.0.1 port=3036 protocol=scgi

All is fine until I want to roll out a new release from the VCS (Bazaar in my case). I made an alias script called up that does the following:

alias up='bzr up; killall manage.py'

It is this generic for one simple reason: I'm lazy. I want one command that I can use under any site to update it. I'm logged into the server most of the time anyway, so, I just hop into the root of the right site and call up. Site updates from BZR and restarts.

The first downside of this is it kills all the manage.py processes on the machine. Currently 6 sites and growing rapidly. The second (and potentially worse -- at least for end-users) is it's a severely non-graceful restart. If somebody was uploading an image or doing something else with a long connection time, their request would just die on the vine.

So what I'm looking for is suggestions for a single method that:

  1. Is generic for lazy people like me (eg I can run it from any site root without having to remember which command I need to call; 'up' is perfect in name.
  2. Only kills the current site. I'm only updating the current site, so only this one should die.
  3. Does the restart in a graceful manner. If possible, it should wait until there are no more active connections. I've no idea how feasible this is.
+2  A: 
Steve Losh