From 298938de736d83126b94226c67ac449aedcb5a4e Mon Sep 17 00:00:00 2001 From: James Valleroy Date: Wed, 3 Dec 2014 22:10:24 -0500 Subject: [PATCH] Signal xmpp module before and after hostname is changed. --- plinth/modules/config/config.py | 13 +++++++++---- plinth/modules/xmpp/xmpp.py | 28 ++++++++++++++++++++++++++++ plinth/signals.py | 2 ++ 3 files changed, 39 insertions(+), 4 deletions(-) diff --git a/plinth/modules/config/config.py b/plinth/modules/config/config.py index 4d6398389..d91215d45 100644 --- a/plinth/modules/config/config.py +++ b/plinth/modules/config/config.py @@ -31,6 +31,7 @@ import socket from plinth import actions from plinth import cfg +from plinth.signals import pre_hostname_change, post_hostname_change LOGGER = logging.getLogger(__name__) @@ -160,9 +161,13 @@ def set_hostname(hostname): # valid_hostname check, convert to ASCII. hostname = str(hostname) + pre_hostname_change.send_robust(sender='config', + old_hostname=old_hostname, + new_hostname=hostname) + LOGGER.info('Changing hostname to - %s', hostname) - actions.superuser_run('xmpp-pre-hostname-change') actions.superuser_run('hostname-change', hostname) - actions.superuser_run('xmpp', 'change-hostname', - '--old-hostname', old_hostname, - '--new-hostname', hostname, async=True) + + post_hostname_change.send_robust(sender='config', + old_hostname=old_hostname, + new_hostname=hostname) diff --git a/plinth/modules/xmpp/xmpp.py b/plinth/modules/xmpp/xmpp.py index 3a67c14a8..fe4a21ef0 100644 --- a/plinth/modules/xmpp/xmpp.py +++ b/plinth/modules/xmpp/xmpp.py @@ -26,6 +26,7 @@ import logging from plinth import actions from plinth import cfg from plinth import service +from plinth.signals import pre_hostname_change, post_hostname_change LOGGER = logging.getLogger(__name__) @@ -53,6 +54,9 @@ def init(): 'xmpp-bosh', _('Chat Server - web interface'), is_external=True, enabled=True) + pre_hostname_change.connect(on_pre_hostname_change) + post_hostname_change.connect(on_post_hostname_change) + @login_required def index(request): @@ -178,3 +182,27 @@ def _register_user(request, data): messages.error(request, _('Failed to register account for %s: %s') % (data['username'], output)) + + +def on_pre_hostname_change(sender, old_hostname, new_hostname, **kwargs): + """ + Backup ejabberd database before hostname is changed. + """ + del sender # Unused + del old_hostname # Unused + del new_hostname # Unused + del kwargs # Unused + + actions.superuser_run('xmpp-pre-hostname-change') + + +def on_post_hostname_change(sender, old_hostname, new_hostname, **kwargs): + """ + Update ejabberd and jwchat config after hostname is changed. + """ + del sender # Unused + del kwargs # Unused + + actions.superuser_run('xmpp', 'change-hostname', + '--old-hostname', old_hostname, + '--new-hostname', hostname, async=True) diff --git a/plinth/signals.py b/plinth/signals.py index f02002289..e5e5d718c 100644 --- a/plinth/signals.py +++ b/plinth/signals.py @@ -25,3 +25,5 @@ from django.dispatch import Signal service_enabled = Signal(providing_args=['service_id', 'enabled']) pre_module_loading = Signal() post_module_loading = Signal() +pre_hostname_change = Signal(providing_args=['old_hostname', 'new_hostname']) +post_hostname_change = Signal(providing_args=['old_hostname', 'new_hostname'])