views:

85

answers:

1

I'm using Capistrano to deploy a Django application (it uses Nginx as the web server), using instructions I found at http://akashxav.com/2009/07/11/getting-django-running-on-nginx-and-fastcgi-on-prgmr/ (I had to look at a cached version earlier today) and was wondering about the last command in there, which is

python manage.py runfcgi host=127.0.0.1 port=8081 --settings=settings

I understand at a high level that this is telling the application that we want to run a few instances of the FastCGI binary to serve up this application.

What I was wondering is how is the best way to handle "resetting" this, for lack of a better word. For those who don't know, Capistrano deploys things by creating "releases" directories and then providing a symlink to the latest release.

Since I can do post-deployment tasks (I've done this with CakePHP applications to do things like properly set directory permissions for a caching directory in the application) I was wondering how to turn off the existing processes created by the command above and start up new ones.

I hope I am making sense.

+1  A: 

There is a section in the django docs about this

Basically use the pidfile option to manage.py and then write a small shell script to use that pid to kill the existing cgi process if it exists before starting the new one.

Something like this

#!/bin/bash
if [ -f "pidfile" ]; then
    kill `cat -- pidfile`
    rm -f -- pidfile
fi
exec python manage.py runfcgi host=127.0.0.1 port=8081 pidfile=pidfile --settings=settings
Nick Craig-Wood