2008-12-30 17:25:42 +01:00
|
|
|
# This file is part of Radicale Server - Calendar Server
|
2009-07-27 17:04:54 +02:00
|
|
|
# Copyright © 2008 Nicolas Kandel
|
|
|
|
# Copyright © 2008 Pascal Halter
|
2017-05-27 17:28:07 +02:00
|
|
|
# Copyright © 2008-2017 Guillaume Ayoub
|
2019-06-17 04:13:25 +02:00
|
|
|
# Copyright © 2017-2019 Unrud <unrud@outlook.com>
|
2008-12-30 17:25:42 +01:00
|
|
|
#
|
|
|
|
# This library is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This library is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with Radicale. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2010-01-19 20:31:21 +01:00
|
|
|
"""
|
2020-01-12 23:32:28 +01:00
|
|
|
Entry point for external WSGI servers (like uWSGI or Gunicorn).
|
2010-01-19 20:31:21 +01:00
|
|
|
|
2020-01-12 23:32:28 +01:00
|
|
|
Configuration files can be specified in the environment variable
|
|
|
|
``RADICALE_CONFIG``.
|
2010-01-19 20:31:21 +01:00
|
|
|
|
|
|
|
"""
|
|
|
|
|
2016-08-02 14:37:39 +02:00
|
|
|
import os
|
|
|
|
import threading
|
2008-12-30 17:25:42 +01:00
|
|
|
|
2019-06-05 01:54:04 +02:00
|
|
|
import pkg_resources
|
2016-04-22 04:37:02 +02:00
|
|
|
|
2018-08-28 16:19:36 +02:00
|
|
|
from radicale import config, log
|
|
|
|
from radicale.app import Application
|
2018-01-14 18:29:37 +01:00
|
|
|
|
2018-08-18 12:56:40 +02:00
|
|
|
VERSION = pkg_resources.get_distribution("radicale").version
|
2010-05-31 00:49:52 +02:00
|
|
|
|
2018-04-20 22:53:42 +02:00
|
|
|
_application = None
|
2018-04-29 21:45:34 +02:00
|
|
|
_application_config_path = None
|
2018-04-20 22:53:42 +02:00
|
|
|
_application_lock = threading.Lock()
|
|
|
|
|
|
|
|
|
2018-08-16 07:59:56 +02:00
|
|
|
def _init_application(config_path, wsgi_errors):
|
2018-04-29 21:45:34 +02:00
|
|
|
global _application, _application_config_path
|
2018-04-29 21:43:10 +02:00
|
|
|
with _application_lock:
|
|
|
|
if _application is not None:
|
|
|
|
return
|
2018-08-16 07:59:55 +02:00
|
|
|
log.setup()
|
2018-08-16 07:59:56 +02:00
|
|
|
with log.register_stream(wsgi_errors):
|
|
|
|
_application_config_path = config_path
|
2019-06-17 04:13:25 +02:00
|
|
|
configuration = config.load(config.parse_compound_paths(
|
|
|
|
config.DEFAULT_CONFIG_PATH,
|
|
|
|
config_path))
|
2018-08-16 08:00:02 +02:00
|
|
|
log.set_level(configuration.get("logging", "level"))
|
2020-01-12 23:32:25 +01:00
|
|
|
# Log configuration after logger is configured
|
|
|
|
configuration.log_config_sources()
|
2018-08-16 07:59:56 +02:00
|
|
|
_application = Application(configuration)
|
2018-04-29 21:43:10 +02:00
|
|
|
|
|
|
|
|
|
|
|
def application(environ, start_response):
|
2020-01-12 23:32:28 +01:00
|
|
|
"""Entry point for external WSGI servers."""
|
2018-08-16 07:57:32 +02:00
|
|
|
config_path = environ.get("RADICALE_CONFIG",
|
|
|
|
os.environ.get("RADICALE_CONFIG"))
|
2018-04-20 22:53:42 +02:00
|
|
|
if _application is None:
|
2018-08-16 07:59:56 +02:00
|
|
|
_init_application(config_path, environ["wsgi.errors"])
|
2018-04-29 21:45:34 +02:00
|
|
|
if _application_config_path != config_path:
|
|
|
|
raise ValueError("RADICALE_CONFIG must not change: %s != %s" %
|
|
|
|
(repr(config_path), repr(_application_config_path)))
|
2018-04-20 22:53:42 +02:00
|
|
|
return _application(environ, start_response)
|