summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBarry Warsaw2017-02-10 12:28:36 -0500
committerBarry Warsaw2017-02-10 12:28:36 -0500
commit0ba2a4ad8398a3ffb4a88761a67e3e9753a435d3 (patch)
tree4fba0b01262faee0ec63c2acbeeb31911e7fdc2d /src
parent7cd3d7e9022a614ef424c266f542c1e5ea52666e (diff)
downloadmailman-0ba2a4ad8398a3ffb4a88761a67e3e9753a435d3.tar.gz
mailman-0ba2a4ad8398a3ffb4a88761a67e3e9753a435d3.tar.zst
mailman-0ba2a4ad8398a3ffb4a88761a67e3e9753a435d3.zip
Diffstat (limited to 'src')
-rw-r--r--src/mailman/rest/gunicorn.py32
1 files changed, 20 insertions, 12 deletions
diff --git a/src/mailman/rest/gunicorn.py b/src/mailman/rest/gunicorn.py
index 79e4ac504..489828715 100644
--- a/src/mailman/rest/gunicorn.py
+++ b/src/mailman/rest/gunicorn.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2015 by the Free Software Foundation, Inc.
+# Copyright (C) 2015-2017 by the Free Software Foundation, Inc.
#
# This file is part of GNU Mailman.
#
@@ -20,7 +20,7 @@
To use this do the following:
* Install gunicorn as a Python 3 application (in a venv if necessary).
-* Create a mailman.cfg with at least the following it it:
+* Create a mailman.cfg with at least the following in it:
[runner.rest]
start: no
@@ -28,25 +28,33 @@ To use this do the following:
* Start Mailman as normal: `mailman start`
* Set the MAILMAN_CONFIG_FILE environment variable to the location of your
mailman.cfg file from above.
-* Run: gunicorn mailman.rest.gunicorn:make_application
+* Run: gunicorn mailman.rest.gunicorn:run
"""
-__all__ = [
- 'make_application',
- ]
+from public import public
-# Initializing the Mailman system once.
-from mailman.core.initialize import initialize
-initialize()
-from mailman.rest.wsgiapp import make_application as base_application
-app = base_application()
+_initialized = False
-def make_application(environ, start_response):
+
+@public
+def run(environ, start_response):
"""Create the WSGI application.
Use this if you want to integrate Mailman's REST server with an external
WSGI server, such as gunicorn. Be sure to set the $MAILMAN_CONFIG_FILE
environment variable.
"""
+ # Imports are here to evaluate them lazily, prevent circular imports, and
+ # make flake8 happy.
+ global _initialized
+ if not _initialized:
+ from mailman.core.initialize import initialize
+ # First things first, initialize the system before any other imports or
+ # other operations. It must only be initialized once though.
+ initialize(propagate_logs=True)
+ _initialized = True
+ # Hook things up to WSGI.
+ from mailman.rest.wsgiapp import make_application
+ app = make_application()
return app(environ, start_response)