From 2c59bbe0f32b0779ce5373f27e5931d0a8faed2d Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Mon, 14 Jan 2019 15:15:14 -0800 Subject: [PATCH] action_utils: Implement utilities for managing uwsgi configurations Signed-off-by: Sunil Mohan Adapa Reviewed-by: James Valleroy --- plinth/action_utils.py | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/plinth/action_utils.py b/plinth/action_utils.py index 370e52889..caf2a1acd 100644 --- a/plinth/action_utils.py +++ b/plinth/action_utils.py @@ -30,6 +30,9 @@ from django.utils.translation import ugettext as _ logger = logging.getLogger(__name__) +UWSGI_ENABLED_PATH = '/etc/uwsgi/apps-enabled/{config_name}.ini' +UWSGI_AVAILABLE_PATH = '/etc/uwsgi/apps-available/{config_name}.ini' + def is_systemd_running(): """Return if we are running under systemd.""" @@ -245,6 +248,43 @@ class WebserverChange(object): self.actions_required.add(action_required) +def uwsgi_is_enabled(config_name): + """Return whether a config is enabled in Radicale.""" + enabled_path = UWSGI_ENABLED_PATH.format(config_name=config_name) + return os.path.exists(enabled_path) + + +def uwsgi_enable(config_name): + """Enable a uwsgi configuration that runs under uwsgi.""" + if uwsgi_is_enabled(config_name): + return + + # uwsgi is started/stopped using init script. We don't know if it can + # handle some configuration already running against newly enabled + # configuration. So, stop first before enabling new configuration. + service_stop('uwsgi') + + enabled_path = UWSGI_ENABLED_PATH.format(config_name=config_name) + available_path = UWSGI_AVAILABLE_PATH.format(config_name=config_name) + os.symlink(available_path, enabled_path) + + service_enable('uwsgi') + service_start('uwsgi') + + +def uwsgi_disable(config_name): + """Disable a uwsgi configuration that runs under uwsgi.""" + if not uwsgi_is_enabled(config_name): + return + + # If uwsgi is restarted later, it won't stop the just disabled + # configuration due to how init scripts are written for uwsgi. + service_stop('uwsgi') + enabled_path = UWSGI_ENABLED_PATH.format(config_name=config_name) + os.unlink(enabled_path) + service_start('uwsgi') + + def diagnose_port_listening(port, kind='tcp', listen_address=None): """Run a diagnostic on whether a port is being listened on.