简体   繁体   中英

Reloading sources of a CherryPy application behind Apache using Mod_WSGI

I'm serving a CherryPy application object in Apache2 using mod_wsgi. 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:

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:

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:

    '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. 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. The only difference, as far as I can see, is that locally I call cherrypy.tree.mount and in production I call 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. 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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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