Added support for SCGI and AJP. This is a piece that was missed in [4897]. Refs

#3047.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@4902 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Malcolm Tredinnick 2007-04-01 07:30:27 +00:00
parent d882656ea3
commit 70c4a88e82
1 changed files with 17 additions and 8 deletions

View File

@ -1,5 +1,5 @@
""" """
FastCGI server that implements the WSGI protocol. FastCGI (or SCGI, or AJP1.3 ...) server that implements the WSGI protocol.
Uses the flup python package: http://www.saddi.com/software/flup/ Uses the flup python package: http://www.saddi.com/software/flup/
@ -18,15 +18,16 @@ __version__ = "0.1"
__all__ = ["runfastcgi"] __all__ = ["runfastcgi"]
FASTCGI_HELP = r"""runfcgi: FASTCGI_HELP = r"""runfcgi:
Run this project as a fastcgi application. To do this, the Run this project as a fastcgi (or some other protocol supported
flup package from http://www.saddi.com/software/flup/ is by flup) application. To do this, the flup package from
required. http://www.saddi.com/software/flup/ is required.
Usage: Usage:
django-admin.py runfcgi --settings=yourproject.settings [fcgi settings] django-admin.py runfcgi --settings=yourproject.settings [fcgi settings]
manage.py runfcgi [fcgi settings] manage.py runfcgi [fcgi settings]
Optional Fcgi settings: (setting=value) Optional Fcgi settings: (setting=value)
protocol=PROTOCOL fcgi, scgi, ajp, ... (default fcgi)
host=HOSTNAME hostname to listen on.. host=HOSTNAME hostname to listen on..
port=PORTNUM port to listen on. port=PORTNUM port to listen on.
socket=FILE UNIX socket to listen on. socket=FILE UNIX socket to listen on.
@ -45,8 +46,8 @@ Examples:
(for webservers which spawn your processes for you) (for webservers which spawn your processes for you)
$ manage.py runfcgi method=threaded $ manage.py runfcgi method=threaded
Run a fastcgi server on a TCP host/port Run a scgi server on a TCP host/port
$ manage.py runfcgi method=prefork host=127.0.0.1 port=8025 $ manage.py runfcgi protocol=scgi method=prefork host=127.0.0.1 port=8025
Run a fastcgi server on a UNIX domain socket (posix platforms only) Run a fastcgi server on a UNIX domain socket (posix platforms only)
$ manage.py runfcgi method=prefork socket=/tmp/fcgi.sock $ manage.py runfcgi method=prefork socket=/tmp/fcgi.sock
@ -58,6 +59,7 @@ Examples:
""" """
FASTCGI_OPTIONS = { FASTCGI_OPTIONS = {
'protocol': 'fcgi',
'host': None, 'host': None,
'port': None, 'port': None,
'socket': None, 'socket': None,
@ -100,16 +102,17 @@ def runfastcgi(argset=[], **kwargs):
print >> sys.stderr, " installed flup, then make sure you have it in your PYTHONPATH." print >> sys.stderr, " installed flup, then make sure you have it in your PYTHONPATH."
return False return False
flup_module = 'server.' + options['protocol']
if options['method'] in ('prefork', 'fork'): if options['method'] in ('prefork', 'fork'):
from flup.server.fcgi_fork import WSGIServer
wsgi_opts = { wsgi_opts = {
'maxSpare': int(options["maxspare"]), 'maxSpare': int(options["maxspare"]),
'minSpare': int(options["minspare"]), 'minSpare': int(options["minspare"]),
'maxChildren': int(options["maxchildren"]), 'maxChildren': int(options["maxchildren"]),
'maxRequests': int(options["maxrequests"]), 'maxRequests': int(options["maxrequests"]),
} }
flup_module += '_fork'
elif options['method'] in ('thread', 'threaded'): elif options['method'] in ('thread', 'threaded'):
from flup.server.fcgi import WSGIServer
wsgi_opts = { wsgi_opts = {
'maxSpare': int(options["maxspare"]), 'maxSpare': int(options["maxspare"]),
'minSpare': int(options["minspare"]), 'minSpare': int(options["minspare"]),
@ -120,6 +123,12 @@ def runfastcgi(argset=[], **kwargs):
wsgi_opts['debug'] = False # Turn off flup tracebacks wsgi_opts['debug'] = False # Turn off flup tracebacks
try:
WSGIServer = getattr(__import__('flup.' + flup_module, '', '', flup_module), 'WSGIServer')
except:
print "Can't import flup." + flup_module
return False
# Prep up and go # Prep up and go
from django.core.handlers.wsgi import WSGIHandler from django.core.handlers.wsgi import WSGIHandler