From 90c9e3b9a84e31391eb6414be2a7600beef58fc7 Mon Sep 17 00:00:00 2001 From: James Valleroy Date: Thu, 18 Dec 2014 21:56:53 -0500 Subject: [PATCH] Convert xmpp-pre-hostname-change to python, merge into xmpp action file. --- actions/xmpp | 27 +++++++++++++++++++++++++++ actions/xmpp-pre-hostname-change | 27 --------------------------- plinth/modules/xmpp/xmpp.py | 7 ++++--- 3 files changed, 31 insertions(+), 30 deletions(-) delete mode 100755 actions/xmpp-pre-hostname-change diff --git a/actions/xmpp b/actions/xmpp index 6c2dae8f1..66e36bb28 100755 --- a/actions/xmpp +++ b/actions/xmpp @@ -41,6 +41,15 @@ def parse_arguments(): subparsers.add_parser('get-installed', help='Get whether ejabberd is installed') + # Prepare ejabberd for hostname change + pre_hostname_change = subparsers.add_parser( + 'pre-change-hostname', + help='Prepare ejabberd for hostname change') + pre_hostname_change.add_argument('--old-hostname', + help='Previous hostname') + pre_hostname_change.add_argument('--new-hostname', + help='New hostname') + # Update ejabberd and jwchat with new hostname hostname_change = subparsers.add_parser( 'change-hostname', @@ -66,6 +75,24 @@ def subcommand_get_installed(_): print('installed' if get_installed() else 'not installed') +def subcommand_pre_change_hostname(arguments): + """Prepare ejabberd for hostname change""" + if not get_installed(): + print('Failed to update XMPP hostname: ejabberd is not installed.') + return + + old_hostname = arguments.old_hostname + new_hostname = arguments.new_hostname + + subprocess.call(['ejabberdctl', 'dump', EJABBERD_BACKUP]) + subprocess.call(['ejabberdctl', 'stop']) + + # Make sure there aren't files in the Mnesia spool dir + os.makedirs('/var/lib/ejabberd/oldfiles', exist_ok=True) + subprocess.call('mv /var/lib/ejabberd/*.* /var/lib/ejabberd/oldfiles/', + shell=True) + + def subcommand_change_hostname(arguments): """Update ejabberd and jwchat with new hostname""" if not get_installed(): diff --git a/actions/xmpp-pre-hostname-change b/actions/xmpp-pre-hostname-change deleted file mode 100755 index 22a4e70cc..000000000 --- a/actions/xmpp-pre-hostname-change +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/sh -# -# This file is part of Plinth. -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program 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 Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# - -# Action to backup ejabberd database before changing hostname. - -BACKUP=/var/log/ejabberd/ejabberd.dump -ejabberdctl dump $BACKUP -ejabberdctl stop - -# Make sure there aren't files in the Mnesia spool dir -mkdir -p /var/lib/ejabberd/oldfiles -mv /var/lib/ejabberd/*.* /var/lib/ejabberd/oldfiles/ diff --git a/plinth/modules/xmpp/xmpp.py b/plinth/modules/xmpp/xmpp.py index 6d0df3689..503ee8b7c 100644 --- a/plinth/modules/xmpp/xmpp.py +++ b/plinth/modules/xmpp/xmpp.py @@ -189,11 +189,12 @@ 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') + actions.superuser_run('xmpp', + ['pre-change-hostname', + '--old-hostname', old_hostname, + '--new-hostname', new_hostname]) def on_post_hostname_change(sender, old_hostname, new_hostname, **kwargs):