Start CherryPy in environment "staging"

This commit is contained in:
Henri 2020-12-05 22:06:40 +01:00
parent aed7cfd8dd
commit 3aeb1801d9

View File

@ -102,7 +102,11 @@ def run_webapp(cfg):
"""Runs the CherryPy web application with the provided configuration data""" """Runs the CherryPy web application with the provided configuration data"""
script_path = os.path.dirname(os.path.abspath(__file__)) script_path = os.path.dirname(os.path.abspath(__file__))
app = WebApp(cfg) app = WebApp(cfg)
# Configure the web application
app_conf = { app_conf = {
'global': {
'environment' : 'production'
},
'/': { '/': {
'tools.sessions.on': True, 'tools.sessions.on': True,
'tools.staticdir.root': os.path.join(script_path, 'webroot'), 'tools.staticdir.root': os.path.join(script_path, 'webroot'),
@ -127,14 +131,23 @@ def run_webapp(cfg):
'tools.staticfile.filename': os.path.join(script_path, 'webroot', 'static', 'favicon.ico') 'tools.staticfile.filename': os.path.join(script_path, 'webroot', 'static', 'favicon.ico')
} }
} }
# Use SSL if certificate files exist
if os.path.exists(cfg.sslcertfile) and os.path.exists(cfg.sslkeyfile): if os.path.exists(cfg.sslcertfile) and os.path.exists(cfg.sslkeyfile):
# Use ssl/tls if certificate files are present # Use ssl/tls if certificate files are present
cherrypy.server.ssl_module = 'builtin' cherrypy.server.ssl_module = 'builtin'
cherrypy.server.ssl_certificate = cfg.sslcertfile cherrypy.server.ssl_certificate = cfg.sslcertfile
cherrypy.server.ssl_private_key = cfg.sslkeyfile cherrypy.server.ssl_private_key = cfg.sslkeyfile
# Define socket parameters
cherrypy.config.update({'server.socket_host': cfg.socket_host, cherrypy.config.update({'server.socket_host': cfg.socket_host,
'server.socket_port': cfg.socket_port, 'server.socket_port': cfg.socket_port,
}) })
# Select environment
cherrypy.config.update({'staging':
{
'environment' : 'production'
}
})
# Start CherryPy
cherrypy.tree.mount(app, config=app_conf) cherrypy.tree.mount(app, config=app_conf)
if setupenv.is_root(): if setupenv.is_root():
# Drop privileges # Drop privileges