简体   繁体   English

如何调试重新启动mod_wsgi进程的apache?

[英]How do I debug apache restarting a mod_wsgi process?

How can I debug apache to understand why it's restarting a mod_wsgi process? 如何调试apache以了解为什么重新启动mod_wsgi进程? And how can this happen? 怎么会这样呢?

I have a django application running Apache/2.4.7 (Ubuntu) with mod_wsgi - single process, multi-threaded. 我有一个运行mod / 2wsgi且运行Apache / 2.4.7(Ubuntu)的django应用程序-单进程,多线程。 I had messages in my python log file which only happen when the process first initializes - only after I manually restart apache... but apache hadn't been restarted. 我的python日志文件中有消息,仅在进程首次初始化时才发生-仅在我手动重启apache之后...但是apache尚未重启。 I didn't see anything in the apache access / error logs either. 我也没有在apache访问/错误日志中看到任何东西。 Does apache ever restart a process on it's own? Apache是​​否会自行重启进程?

A short time later, apache basically stopped servicing any requests - as if it had hung or crashed, and I needed to restart apache. 不久之后,apache基本上停止了为任何请求提供服务-好像它已挂起或崩溃了,我需要重新启动apache。

Never seen this before - is there anything I can monitor to deep dive into the state of apache? 以前从未见过-有什么我可以监视的以深入探究Apache状态吗?

Relevant parts of config look like this: 配置的相关部分如下所示:

###  Apache/sites-enabled/main.wsgi:
<VirtualHost 0.0.0.0:443>
    SSLEngine on
    SSLCertificateFile ...
    SSLCertificateKeyFile ...
    SSLCACertificateFile ...

    Options ExecCGI FollowSymLinks MultiViews

    AddHandler wsgi-script .wsgi
    WSGIDaemonProcess myapp
    WSGIProcessGroup myapp
    WSGIScriptAlias / /myproject/myapp.wsgi

    <Directory /myproject/scripts>
        <Files myapp.wsgi>
            Require all granted
        </Files>
    </Directory>
</VirtualHost>


####  /myproject/scripts/myapp.wsgi:
#!/usr/bin/python
import os
import sys
sys.path.append('/usr/local/lib/python2.7/site-packages')
sys.path.append('/myproject')
os.environ['DJANGO_SETTINGS_MODULE'] = 'myapp.settings'
os.environ['PYTHON_EGG_CACHE'] = '/tmp'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

In addition to the custom initialization log entries indicating the process restarted, I noticed the following in the apache-error.log: 除了指示进程已重新启动的自定义初始化日志条目外,我还在apache-error.log中注意到以下内容:

[Mon Sep 15 17:43:35 2014] [core:error] [pid 2801:tid 140079485876000] [client 111.111.111.111:64444] End of script output before headers: myapp.wsgi, referer: https://mysite.com/login.html

Set Apache LogLevel to 'info': 将Apache LogLevel设置为“ info”:

LogLevel info

This will cause mod_wsgi to output more messages about the restart of daemon processes. 这将导致mod_wsgi输出更多有关重新启动守护进程的消息。

Provide the log messages for that. 为此提供日志消息。

Also ensure that nothing is running in embedded mode by mistake. 另外,请确保没有任何错误地在嵌入式模式下运行。

WSGIRestrictEmbedded On

If your application is hanging, then the issue may be that you are using Python modules that do not work in Python sub interpreters. 如果您的应用程序挂起,则问题可能出在您使用的Python模块在Python子解释器中不起作用。 To combat that, set: 为了解决这个问题,请设置:

WSGIApplicationGroup %{GLOBAL}

For details about this see: 有关此的详细信息,请参见:

You might also watch: 您可能还会看:

It explains a lot about how Apache can restart processes if using embedded mode and the problems that can cause. 它解释了很多有关Apache在使用嵌入式模式时如何重新启动进程的信息以及可能引起的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM