Django Apache FastCGI重启

时间:2011-02-22 21:59:34

标签: django apache fastcgi restart

根据Django文档,可以使用FastCGI配置Django。

这是我们的设置(请注意,我不在我的工作场所控制Apache设置,因为我们已经拥有它而不是安装WSGI,所以我需要使用FastCGI):

我们apache conf的fcgi相关部分是:

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

最后一行应该是最相关的。我的django.fcgi是:

#!/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")

根据

http://docs.djangoproject.com/en/dev/howto/deployment/fastcgi/#restarting-the-spawned-server

重新启动fcgi应该像

一样简单
touch django.fcgi

但对我们来说,它不会导致重启(这就是我将pid写入文件的原因)。

为什么触摸django.fcgi不起作用?

2 个答案:

答案 0 :(得分:0)

我不知道,但我可以提出一个不涉及安装任何东西的替代解决方案:

只需在某个任意localhost端口(比如50000)上运行django,然后执行以下操作:

RewriteEngine On
RewriteRule ^(.*)$ http://localhost:50000/$1 [P]

它需要的只是标准的mod_rewrite和mod_proxy。

答案 1 :(得分:0)

好的,然后是你问题的实际答案。 :)

看起来你错过了一个选项。

  

-autoUpdate(none)

     

使mod_fastcgi检查应用程序的修改时间   在处理每个请求之前在磁盘上。如果磁盘上的应用程序已更改,则会通知进程管理器,并且应用程序的所有正在运行的实例都将被终止。通常,最好将这种类型的功能内置到应用程序中(例如,它检查每100个请求以查看磁盘上是否有更新的版本,如果是,则退出)。当此选项与-restart一起使用时,可能存在一个未解决的问题(bug)。

- http://www.fastcgi.com/mod_fastcgi/docs/mod_fastcgi.html#FastCgiConfig