You are not logged in.

  • Index
  •  » Django
  •  » Setting up Django with nginx/FastCGI.

#26 2009-08-24 11:35:23

frozenskys
Member
From: Northampton, UK
Registered: 2009-01-23
Posts: 70
Website

Re: Setting up Django with nginx/FastCGI.

Glad I could help smile

There is one main django fcgi process and one spare fcgi process these are defined by the manage.py runfcgi command line options:

Code:

  maxspare=NUMBER      max number of spare processes or threads 
  minspare=NUMBER      min number of spare processes or threads
  maxchildren=NUMBER   hard limit number of processes or threads

Changing these will give you more (or less) processes shown in ps

Regards,
Richard.

Offline

 

#27 2009-09-01 05:51:52

frozenskys
Member
From: Northampton, UK
Registered: 2009-01-23
Posts: 70
Website

Re: Setting up Django with nginx/FastCGI.

How would you write a custom restart script for both Nginx and Django in this instance? will the original startup lines e.g.

Code:

./sbin/nginx
python2.5 manage.py runfcgi maxchildren=1 maxspare=1 method=prefork socket=/home/user/webapps/app/app.sock

in a cron job work?

Offline

 

#28 2009-09-01 15:02:31

mae
Member
Registered: 2006-10-14
Posts: 445

Re: Setting up Django with nginx/FastCGI.

Code:

./sbin/nginx && /usr/local/bin/python2.5 manage.py runfcgi maxchildren=1 maxspare=1 method=prefork socket=/home/user/webapps/app/app.sock

You should && them if nginx was restarted correctly then restart django.

Also please note I put the full path to python2.5 you should do the same for your manage.py as cron know nothing about the path it's executed in.

Offline

 

#29 2009-09-01 15:09:38

frozenskys
Member
From: Northampton, UK
Registered: 2009-01-23
Posts: 70
Website

Re: Setting up Django with nginx/FastCGI.

Thanks, that helps a lot! smile

Offline

 

#30 2009-09-02 02:21:00

frozenskys
Member
From: Northampton, UK
Registered: 2009-01-23
Posts: 70
Website

Re: Setting up Django with nginx/FastCGI.

Actually no it doesn't - the manage.py command doesn't check if the process is already running and starts another process each time sad

I need to be able to handle the following.
    1) Both processes already running - don't do anything.
    2) Nginx Running / Django Down - restart django.
    3) Nginx Down / Django Running - restart nginx.
    4) Both processes down - restart nginx then django.

My scripting skills are no that hot - anyone here able to help me - or at least point me in the right direction so that I don't get my wrists slapped by the WebFaction support team for using all their memory! smile

Thanks,
Richard.

Offline

 

#31 2009-09-03 09:24:34

seanf
Administrator
Registered: 2008-02-01
Posts: 1899
Website

Re: Setting up Django with nginx/FastCGI.

I think you should look into using Supervisor: http://supervisord.org/

If you don't want to use that, then you can grep your process listing for whatever command and use the result as a condition, eg:

Code:

CMD="/usr/local/bin/python2.5 manage.py runfcgi maxchildren=1 maxspare=1 method=prefork socket=/home/user/webapps/app/app.sock"
ps -u your_username -o command | grep -v grep | grep $CMD || $CMD

In other words:

1. Define the command that should be running

2. Get a list of your currently running commands

3. Look for the command

4. Run it if it's not there

Offline

 

#32 2009-09-03 09:40:55

frozenskys
Member
From: Northampton, UK
Registered: 2009-01-23
Posts: 70
Website

Re: Setting up Django with nginx/FastCGI.

Thanks! I'll check out Supervisor - It looks good, but I'll need to check it's effect on memory usage etc. I assume I can install it with the usual easy_install command e.g.

Code:

easy_install-2.5 -s $HOME/bin -d $HOME/lib/python2.5 supervisor

The other question of course being "How do I make sure that Supervisor is running (e.g. after a server reboot)?"

Also I've knocked up a bash script which I'm currently testing on my local server which uses pid files to start and stop nginx and django together. It also checks if they are already running before trying to start them.

Last edited by frozenskys (2009-09-03 09:49:05)

Offline

 

#33 2009-09-03 14:55:28

mae
Member
Registered: 2006-10-14
Posts: 445

Re: Setting up Django with nginx/FastCGI.

actually that's not needed just do

Code:

easy_install-2.5 supervisor

and our system will do the right thing.


As for the supervisor question that's a problem indeed. It's a recursive issue much like "who polices the police", in other words you need something to make sure that your something you have to make sure things are running is running smile

What I personally do is create cronjob to monitor supervisor, luckily for you we monitor that crond is always running smile

Offline

 

#34 2009-09-03 15:05:15

frozenskys
Member
From: Northampton, UK
Registered: 2009-01-23
Posts: 70
Website

Re: Setting up Django with nginx/FastCGI.

Indeed... "Who watches the watchmen?"

Thanks for all the help!

smile

Offline

 

#35 2010-01-28 16:11:51

bwooceli
Member
Registered: 2009-02-09
Posts: 15

Re: Setting up Django with nginx/FastCGI.

FYI I've been unable to make flup 1.0.3 work.  It dies with

Code:

AttributeError: 'CGIRequest' object has no attribute '_timeout'

Solved by using flup 1.0.2

Offline

 

#36 2010-02-01 19:46:50

tkirke
Member
Registered: 2010-02-01
Posts: 7

Re: Setting up Django with nginx/FastCGI.

It seems like these instructions work if you are starting from scratch.
If one already has Django & an app up and running, can one switch over to nginx without reinstalling django, etc?
Thanks

Offline

 
  • Index
  •  » Django
  •  » Setting up Django with nginx/FastCGI.

Board footer

Powered by PunBB
© Copyright 2002–2005 Rickard Andersson