Django Apache FastCGI restart
According to Django docs Django can be configured with FastCGI.
Here's our setup (note that I don't control Apache setup at my workplace and I'm required to use FastCGI since we alread开发者_JAVA百科y have it, rather than install WSGI):
The fcgi-relevant part of our apache conf is:
LoadModule fastcgi_module modules/mod_fastcgi.so
# IPC directory location
#
FastCgiIpcDir "/path/to/FastCGI_IPC"
# General CGI config
#
FCGIConfig -idle-timeout 30 -listen-queue-depth 4 -maxProcesses 40 -minProcesses 10 -maxClassProcesses 2 -killInterval 60 -updateInterval 20 -singleThreshhold 0 -multiThreshhold 10 -processSlack 5 -failed-restart-delay 10
# To use FastCGI scripts:
#
AddHandler fastcgi-script .fcg .fcgi .fpl
FastCgiServer "/path/to/my/django.fcgi" -listen-queue-depth 24 -processes 8 -restart-delay 1 -min-server-life 2 -failed-restart-delay 10
The last line should be most relevant. My django.fcgi is:
#!/path/to/python-2.5/bin/python
import sys, os
open('pid', "w").write("%d" % (os.getpid()))
# Add a custom Python path.
sys.path.insert(0, "/path/to/django/")
sys.path.insert(0, "/path/to/python2.5/site-packages/")
# Switch to the directory of your project. (Optional.)
os.chdir("/path/to/django/site")
# Set the DJANGO_SETTINGS_MODULE environment variable.
os.environ['DJANGO_SETTINGS_MODULE'] = "site.settings"
from django.core.servers.fastcgi import runfastcgi
runfastcgi(method="threaded", daemonize="false")
According to
http://docs.djangoproject.com/en/dev/howto/deployment/fastcgi/#restarting-the-spawned-server
restarting the fcgi should be as simple as
touch django.fcgi
but for us it doesn't result in a restart (which is why I'm writing the pid's to files).
Why doesn't the touch django.fcgi work?
I don't know, but I can propose an alternate solution that doesn't involve installing anything:
Just run django on some arbitrary localhost port (say 50000), and then do this:
RewriteEngine On
RewriteRule ^(.*)$ http://localhost:50000/$1 [P]
All it requires are the standard mod_rewrite and mod_proxy.
Okay, an actual answer to your question, then. :)
Looks like you're missing an option.
-autoUpdate (none)
Causes mod_fastcgi to check the modification time of the application on disk before processing each request. If the application on disk has been changed, the process manager is notified and all running instances of the application are killed off. In general, it's preferred that this type of functionality be built-in to the application (e.g. every 100th request it checks to see if there's a newer version on disk and exits if so). There may be an outstanding problem (bug) when this option is used with -restart.
-- http://www.fastcgi.com/mod_fastcgi/docs/mod_fastcgi.html#FastCgiConfig
精彩评论