Merge branch 'i18n' into 'master'
[mailman.git] / contrib / gunicorn.py
bloba0e9b53d11bddbe8d1ca8760453ee078cd6120d6
1 # Copyright (C) 2015-2018 by the Free Software Foundation, Inc.
3 # This file is part of GNU Mailman.
5 # GNU Mailman is free software: you can redistribute it and/or modify it under
6 # the terms of the GNU General Public License as published by the Free
7 # Software Foundation, either version 3 of the License, or (at your option)
8 # any later version.
10 # GNU Mailman is distributed in the hope that it will be useful, but WITHOUT
11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 # more details.
15 # You should have received a copy of the GNU General Public License along with
16 # GNU Mailman. If not, see <https://www.gnu.org/licenses/>.
18 """Experimental Gunicorn based REST server.
20 To use this do the following:
22 * Install gunicorn as a Python 3 application (in a venv if necessary).
23 * Copy this file into your Python's site-packages under the name mmgunicorn.py
24 * Create a mailman.cfg with at least the following in it:
26 [runner.rest]
27 start: no
29 * Start Mailman as normal: `mailman start`
30 * Set the MAILMAN_CONFIG_FILE environment variable to the location of your
31 mailman.cfg file from above.
32 * Run: gunicorn mmgunicorn:run
33 """
35 from public import public
38 _initialized = False
41 @public
42 def run(environ, start_response):
43 """Create the WSGI application.
45 Use this if you want to integrate Mailman's REST server with an external
46 WSGI server, such as gunicorn. Be sure to set the $MAILMAN_CONFIG_FILE
47 environment variable.
48 """
49 # Imports are here to evaluate them lazily, prevent circular imports, and
50 # make flake8 happy.
51 global _initialized
52 if not _initialized:
53 from mailman.core.initialize import initialize
55 # First things first, initialize the system before any other imports or
56 # other operations. It must only be initialized once though.
57 initialize(propagate_logs=True)
58 _initialized = True
59 # Hook things up to WSGI.
60 from mailman.rest.wsgiapp import make_application
61 app = make_application()
62 return app(environ, start_response)