From 974a0146f2a69a16c4766de5699aa4fa6fe939e7 Mon Sep 17 00:00:00 2001 From: James Valleroy Date: Wed, 26 Mar 2014 18:50:55 -0400 Subject: [PATCH 1/5] When changing hostname, also update ejabberd and jwchat. --- actions/xmpp-hostname-change | 67 ++++++++++++++++++++++++++++++ actions/xmpp-pre-hostname-change | 24 +++++++++++ modules/installed/system/config.py | 2 + 3 files changed, 93 insertions(+) create mode 100755 actions/xmpp-hostname-change create mode 100755 actions/xmpp-pre-hostname-change diff --git a/actions/xmpp-hostname-change b/actions/xmpp-hostname-change new file mode 100755 index 000000000..a417b7592 --- /dev/null +++ b/actions/xmpp-hostname-change @@ -0,0 +1,67 @@ +#!/bin/bash + +# +# 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 set up new hostname for ejabberd and jwchat. + +hostname="$1" +old_hostname=`debconf-show ejabberd | awk '/hostname/ { print $3 }'` + +# Based on http://www.process-one.net/docs/ejabberd/guide_en.html#htoc77 + +# Setup some variables +OLDNODE=ejabberd@"$old_hostname" +NEWNODE=ejabberd@"$hostname" +OLDFILE=/tmp/old.backup +NEWFILE=/tmp/new.backup + +echo "ejabberd ejabberd/hostname string $hostname" | debconf-set-selections +echo "jwchat jwchat/ApacheServerName string $hostname" | debconf-set-selections +DEBIAN_FRONTEND=noninteractive dpkg-reconfigure jwchat + +# Debconf can't handle our manual changes to ejabberd's config yet. +sed -i "s/$old_hostname/$hostname/g" /etc/ejabberd/ejabberd.cfg + +# 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/ + +# Start ejabberd +service ejabberd restart + +# It can take a while to start up... +for i in {1..12} +do + if ejabberdctl status ; then + break + else + sleep 10 + fi +done + +# Convert the backup to new node name +ejabberdctl mnesia_change_nodename $OLDNODE $NEWNODE $OLDFILE $NEWFILE + +# Install the backup file as a fallback +ejabberdctl install_fallback $NEWFILE + +# Stop ejabberd +ejabberdctl stop + +# Start ejabberd +service ejabberd restart diff --git a/actions/xmpp-pre-hostname-change b/actions/xmpp-pre-hostname-change new file mode 100755 index 000000000..95c1e4d7a --- /dev/null +++ b/actions/xmpp-pre-hostname-change @@ -0,0 +1,24 @@ +#!/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. + +OLDFILE=/tmp/old.backup +ejabberdctl backup $OLDFILE +ejabberdctl stop diff --git a/modules/installed/system/config.py b/modules/installed/system/config.py index 7d352beb9..dc00f9124 100644 --- a/modules/installed/system/config.py +++ b/modules/installed/system/config.py @@ -55,7 +55,9 @@ def set_hostname(hostname): cfg.log.info("Changing hostname to '%s'" % hostname) try: + superuser_run("xmpp-pre-hostname-change") superuser_run("hostname-change", hostname) + superuser_run("xmpp-hostname-change", hostname, async=True) # don't persist/cache change unless it was saved successfuly sys_store = filedict_con(cfg.store_file, 'sys') sys_store['hostname'] = hostname From 2c41e63889685192c28865d7d007faba0d8cda44 Mon Sep 17 00:00:00 2001 From: James Valleroy Date: Wed, 26 Mar 2014 18:58:36 -0400 Subject: [PATCH 2/5] Restart avahi-daemon after changing hostname to update mdns. --- actions/hostname-change | 2 ++ 1 file changed, 2 insertions(+) diff --git a/actions/hostname-change b/actions/hostname-change index ad71edc80..abb7b293f 100755 --- a/actions/hostname-change +++ b/actions/hostname-change @@ -8,3 +8,5 @@ if [ -x /etc/init.d/hostname.sh ] ; then else service hostname start fi + +service avahi-daemon restart From dadfb2220a58635933588bafaec5ebe5d1d0bb1b Mon Sep 17 00:00:00 2001 From: James Valleroy Date: Tue, 1 Apr 2014 21:17:38 -0500 Subject: [PATCH 3/5] Rearrange xmpp hostname change scripts so we can only restart ejabberd once. --- actions/xmpp-hostname-change | 35 +++++++++++++------------------- actions/xmpp-pre-hostname-change | 4 +++- 2 files changed, 17 insertions(+), 22 deletions(-) diff --git a/actions/xmpp-hostname-change b/actions/xmpp-hostname-change index a417b7592..2c209b052 100755 --- a/actions/xmpp-hostname-change +++ b/actions/xmpp-hostname-change @@ -37,6 +37,18 @@ DEBIAN_FRONTEND=noninteractive dpkg-reconfigure jwchat # Debconf can't handle our manual changes to ejabberd's config yet. sed -i "s/$old_hostname/$hostname/g" /etc/ejabberd/ejabberd.cfg +# Install the backup file as a fallback +ejabberdctl --node $OLDNODE install_fallback $NEWFILE + +# Convert the backup to new node name +ejabberdctl --node $OLDNODE mnesia_change_nodename $OLDNODE $NEWNODE $OLDFILE $NEWFILE + +# Stop ejabberd +ejabberdctl --node $OLDNODE stop + +# Wait for old node to completely shutdown +sleep 10 + # 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/ @@ -44,24 +56,5 @@ mv /var/lib/ejabberd/*.* /var/lib/ejabberd/oldfiles/ # Start ejabberd service ejabberd restart -# It can take a while to start up... -for i in {1..12} -do - if ejabberdctl status ; then - break - else - sleep 10 - fi -done - -# Convert the backup to new node name -ejabberdctl mnesia_change_nodename $OLDNODE $NEWNODE $OLDFILE $NEWFILE - -# Install the backup file as a fallback -ejabberdctl install_fallback $NEWFILE - -# Stop ejabberd -ejabberdctl stop - -# Start ejabberd -service ejabberd restart +# Remove old hostname from /etc/hosts +sed -i "/$old_hostname/d" /etc/hosts diff --git a/actions/xmpp-pre-hostname-change b/actions/xmpp-pre-hostname-change index 95c1e4d7a..f5a6a1645 100755 --- a/actions/xmpp-pre-hostname-change +++ b/actions/xmpp-pre-hostname-change @@ -21,4 +21,6 @@ OLDFILE=/tmp/old.backup ejabberdctl backup $OLDFILE -ejabberdctl stop + +# Add old hostname to /etc/hosts so we can still access the running node. +echo "127.0.0.1 `hostname`" >>/etc/hosts From 415e89c02a1bb479f7cbd9c34375ce63345e9145 Mon Sep 17 00:00:00 2001 From: James Valleroy Date: Sat, 12 Apr 2014 15:47:15 -0400 Subject: [PATCH 4/5] When changing XMPP hostname, make sure user accounts get copied to new database. We are back to 2 ejabberd restarts though. --- actions/xmpp-hostname-change | 28 +++++++--------------------- actions/xmpp-pre-hostname-change | 10 ++++++---- 2 files changed, 13 insertions(+), 25 deletions(-) diff --git a/actions/xmpp-hostname-change b/actions/xmpp-hostname-change index 2c209b052..a9f454134 100755 --- a/actions/xmpp-hostname-change +++ b/actions/xmpp-hostname-change @@ -27,8 +27,7 @@ old_hostname=`debconf-show ejabberd | awk '/hostname/ { print $3 }'` # Setup some variables OLDNODE=ejabberd@"$old_hostname" NEWNODE=ejabberd@"$hostname" -OLDFILE=/tmp/old.backup -NEWFILE=/tmp/new.backup +BACKUP=/tmp/ejabberd.dump echo "ejabberd ejabberd/hostname string $hostname" | debconf-set-selections echo "jwchat jwchat/ApacheServerName string $hostname" | debconf-set-selections @@ -36,25 +35,12 @@ DEBIAN_FRONTEND=noninteractive dpkg-reconfigure jwchat # Debconf can't handle our manual changes to ejabberd's config yet. sed -i "s/$old_hostname/$hostname/g" /etc/ejabberd/ejabberd.cfg +sed -i "s/$old_hostname/$hostname/g" $BACKUP -# Install the backup file as a fallback -ejabberdctl --node $OLDNODE install_fallback $NEWFILE - -# Convert the backup to new node name -ejabberdctl --node $OLDNODE mnesia_change_nodename $OLDNODE $NEWNODE $OLDFILE $NEWFILE - -# Stop ejabberd -ejabberdctl --node $OLDNODE stop - -# Wait for old node to completely shutdown -sleep 10 - -# 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/ - -# Start ejabberd service ejabberd restart -# Remove old hostname from /etc/hosts -sed -i "/$old_hostname/d" /etc/hosts +# Load backup database +sleep 10 +ejabberdctl load $BACKUP +ejabberdctl stop +service ejabberd restart diff --git a/actions/xmpp-pre-hostname-change b/actions/xmpp-pre-hostname-change index f5a6a1645..d7dde1ff9 100755 --- a/actions/xmpp-pre-hostname-change +++ b/actions/xmpp-pre-hostname-change @@ -19,8 +19,10 @@ # Action to backup ejabberd database before changing hostname. -OLDFILE=/tmp/old.backup -ejabberdctl backup $OLDFILE +BACKUP=/tmp/ejabberd.dump +ejabberdctl dump $BACKUP +ejabberdctl stop -# Add old hostname to /etc/hosts so we can still access the running node. -echo "127.0.0.1 `hostname`" >>/etc/hosts +# 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/ From fe6803eb9864710579522c9fedd78378310353d1 Mon Sep 17 00:00:00 2001 From: James Valleroy Date: Sat, 12 Apr 2014 17:26:43 -0400 Subject: [PATCH 5/5] Don't need 2nd restart. --- actions/xmpp-hostname-change | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/actions/xmpp-hostname-change b/actions/xmpp-hostname-change index a9f454134..698a01a23 100755 --- a/actions/xmpp-hostname-change +++ b/actions/xmpp-hostname-change @@ -25,8 +25,6 @@ old_hostname=`debconf-show ejabberd | awk '/hostname/ { print $3 }'` # Based on http://www.process-one.net/docs/ejabberd/guide_en.html#htoc77 # Setup some variables -OLDNODE=ejabberd@"$old_hostname" -NEWNODE=ejabberd@"$hostname" BACKUP=/tmp/ejabberd.dump echo "ejabberd ejabberd/hostname string $hostname" | debconf-set-selections @@ -42,5 +40,4 @@ service ejabberd restart # Load backup database sleep 10 ejabberdctl load $BACKUP -ejabberdctl stop -service ejabberd restart +rm $BACKUP