简体   繁体   English

使用Mod_WSGI在Apache之后重新加载CherryPy应用程序的源

[英]Reloading sources of a CherryPy application behind Apache using Mod_WSGI

I'm serving a CherryPy application object in Apache2 using mod_wsgi. 我正在使用mod_wsgi在Apache2中提供CherryPy应用程序对象。 Everything seems to be fine from a user perspective, meaning that he/she can actually reach the application and work with it as intended. 从用户角度看,一切似乎都很好,这意味着他/她实际上可以访问应用程序并按预期使用它。 But the problem I'm facing is signaling code changes due to a new deployment. 但是我面临的问题是由于新的部署而导致代码更改。

Here's the application configuration in Apache: 这是Apache中的应用程序配置:

WSGIDaemonProcess app-name user=someuser group=somegroup processes=4 maximum-requests=1000 inactivity-timeout=3600 umask=0007 python-path="path-to-sources:path-to-python-site-packages"
WSGIScriptAlias /app-url /location/of/wsgi/start/script/wsgi.py
<Directory "/location/or/sources">
  WSGIProcessGroup somename 
</Directory>

The wsgi start script contains the following: wsgi启动脚本包含以下内容:

import sys
import root.index

sys.stdout = sys.stderr


application = root.index.get_wsgi_app()
#which return an object of cherrypy.Application

CherryPy is running in 'production mode' which means: CherryPy在“生产模式”下运行,这意味着:

    'engine.autoreload_on': False,
    'checker.on': False,
    'tools.log_headers.on': False,
    'request.show_tracebacks': False,
    'request.show_mismatched_params': False,
    'log.screen': False,

Afterwards I manually override engine.autoreload_on and set it to True because I want the application to pick up on the code changes and restart, but this does not have the desired affect. 之后,我手动覆盖engine.autoreload_on并将其设置为True,因为我希望应用程序根据代码更改进行重新启动,但是这并没有理想的效果。 I am aware that touching the wsgi script file or restarting Apache should result in what I want, but CherryPy should detect these changes itself and restart accordingly, as it does when running a local development server. 我知道触摸wsgi脚本文件或重新启动Apache应该会得到我想要的结果,但是CherryPy应该自己检测这些更改并相应地重新启动,就像在运行本地开发服务器时一样。 The only difference, as far as I can see, is that locally I call cherrypy.tree.mount and in production I call cherrypy.Application. 据我所知,唯一的区别是在本地我称为cherrypy.tree.mount,在生产中我称为cherrypy.Application。

Bottom-line: how can I get my production application to pick up on code changes and reload? 底线:如何让我的生产应用程序获取代码更改并重新加载?

CherryPy has request handlers (and a WSGI application) like any other WSGI framework. CherryPy具有与其他任何WSGI框架一样的请求处理程序(和WSGI应用程序)。 But it also has an engine , which handles everything that happens outside of the requests themselves. 但是它也有一个引擎 ,可以处理请求本身之外发生的所有事情。 When you're running standalone, that includes a lot of process management: PIDs, daemonization, etc. When you're running inside Apache, a lot of that is done for you, and it can seem like you don't need to run the engine. 当您独立运行时,其中包括许多过程管理:PID,守护进程等。当您在Apache内部运行时,许多工作已为您完成,并且看起来您不需要运行引擎。 Not true. 不对。 You still should run it at least for handling signals, plus logging of any background tasks, and potentially hooking code into thread start and stop. 您仍然至少应运行它以处理信号,并记录所有后台任务,并可能将代码挂接到线程的启动和停止中。 And in this case, the Autoreloader depends on a running engine. 在这种情况下,自动重新加载器取决于运行中的引擎。 See http://docs.cherrypy.org/stable/concepts/engine.html for more about the Engine object and http://tools.cherrypy.org/wiki/ModWSGI for some example code. 有关引擎对象的更多信息,请参见http://docs.cherrypy.org/stable/concepts/engine.html ;有关某些示例代码,请参见http://tools.cherrypy.org/wiki/ModWSGI

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

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