mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-09-19 04:59:01 +00:00
Use mnesia-change-nodename to update ejabberd backup database.
As Sunil suggested, rearrange commands so we can do this with only 1 ejabberd restart.
This commit is contained in:
parent
90c9e3b9a8
commit
126d466dc7
94
actions/xmpp
94
actions/xmpp
@ -30,6 +30,7 @@ import re
|
|||||||
JWCHAT_CONFIG = '/etc/jwchat/config.js'
|
JWCHAT_CONFIG = '/etc/jwchat/config.js'
|
||||||
EJABBERD_CONFIG = '/etc/ejabberd/ejabberd.yml'
|
EJABBERD_CONFIG = '/etc/ejabberd/ejabberd.yml'
|
||||||
EJABBERD_BACKUP = '/var/log/ejabberd/ejabberd.dump'
|
EJABBERD_BACKUP = '/var/log/ejabberd/ejabberd.dump'
|
||||||
|
EJABBERD_BACKUP_NEW = '/var/log/ejabberd/ejabberd_new.dump'
|
||||||
|
|
||||||
|
|
||||||
def parse_arguments():
|
def parse_arguments():
|
||||||
@ -84,13 +85,14 @@ def subcommand_pre_change_hostname(arguments):
|
|||||||
old_hostname = arguments.old_hostname
|
old_hostname = arguments.old_hostname
|
||||||
new_hostname = arguments.new_hostname
|
new_hostname = arguments.new_hostname
|
||||||
|
|
||||||
subprocess.call(['ejabberdctl', 'dump', EJABBERD_BACKUP])
|
subprocess.call(['ejabberdctl', 'backup', EJABBERD_BACKUP])
|
||||||
subprocess.call(['ejabberdctl', 'stop'])
|
try:
|
||||||
|
subprocess.check_output(['ejabberdctl', 'mnesia-change-nodename',
|
||||||
# Make sure there aren't files in the Mnesia spool dir
|
old_hostname, new_hostname,
|
||||||
os.makedirs('/var/lib/ejabberd/oldfiles', exist_ok=True)
|
EJABBERD_BACKUP, EJABBERD_BACKUP_NEW])
|
||||||
subprocess.call('mv /var/lib/ejabberd/*.* /var/lib/ejabberd/oldfiles/',
|
os.remove(EJABBERD_BACKUP)
|
||||||
shell=True)
|
except subprocess.CalledProcessError as err:
|
||||||
|
print('Failed to change hostname in ejabberd backup database: %s', err)
|
||||||
|
|
||||||
|
|
||||||
def subcommand_change_hostname(arguments):
|
def subcommand_change_hostname(arguments):
|
||||||
@ -134,77 +136,29 @@ def subcommand_change_hostname(arguments):
|
|||||||
in_hosts_section = True
|
in_hosts_section = True
|
||||||
conffile.write(line)
|
conffile.write(line)
|
||||||
|
|
||||||
# update ejabberd backup database
|
subprocess.call(['ejabberdctl', 'stop'])
|
||||||
if os.path.exists(EJABBERD_BACKUP):
|
subprocess.call(['service', 'ejabberd', 'stop'])
|
||||||
with open(EJABBERD_BACKUP, 'r') as dumpfile:
|
subprocess.call(['pkill', '-u', 'ejabberd'])
|
||||||
lines = dumpfile.readlines()
|
|
||||||
with open(EJABBERD_BACKUP, 'w') as dumpfile:
|
|
||||||
in_roster = False
|
|
||||||
in_pubsub_node = False
|
|
||||||
for line in lines:
|
|
||||||
if in_roster:
|
|
||||||
if re.match(r'\s+', line):
|
|
||||||
dumpfile.write(line.replace(
|
|
||||||
'>>,<<"' + old_hostname + '">>',
|
|
||||||
'>>,<<"' + new_hostname + '">>'))
|
|
||||||
continue
|
|
||||||
else:
|
|
||||||
in_roster = False # check other cases below
|
|
||||||
|
|
||||||
if in_pubsub_node:
|
# Make sure there aren't files in the Mnesia spool dir
|
||||||
if re.match(r'\s+', line):
|
os.makedirs('/var/lib/ejabberd/oldfiles', exist_ok=True)
|
||||||
dumpfile.write(line.replace(
|
subprocess.call('mv /var/lib/ejabberd/*.* /var/lib/ejabberd/oldfiles/',
|
||||||
'>>,<<"pubsub.' + old_hostname + '">>,<<',
|
shell=True)
|
||||||
'>>,<<"pubsub.' + new_hostname + '">>,<<'))
|
|
||||||
continue
|
|
||||||
else:
|
|
||||||
in_pubsub_node = False # check other cases below
|
|
||||||
|
|
||||||
if re.match(r'\s*{passwd,', line):
|
subprocess.call(['service', 'ejabberd', 'start'])
|
||||||
dumpfile.write(line.replace(
|
|
||||||
'">>,<<"' + old_hostname + '">>},<<"',
|
|
||||||
'">>,<<"' + new_hostname + '">>},<<"'))
|
|
||||||
elif re.match(r'\s*{private_storage,', line):
|
|
||||||
dumpfile.write(line.replace(
|
|
||||||
'>>,<<"' + old_hostname + '">>,<<',
|
|
||||||
'>>,<<"' + new_hostname + '">>,<<'))
|
|
||||||
elif re.match(r'\s*{last_activity,', line):
|
|
||||||
dumpfile.write(line.replace(
|
|
||||||
'>>,<<"' + old_hostname + '">>},',
|
|
||||||
'>>,<<"' + new_hostname + '">>},'))
|
|
||||||
elif re.match(r'\s*{roster,', line):
|
|
||||||
dumpfile.write(line.replace(
|
|
||||||
'>>,<<"' + old_hostname + '">>,',
|
|
||||||
'>>,<<"' + new_hostname + '">>,'))
|
|
||||||
in_roster = True
|
|
||||||
elif re.match(r'\s*{pubsub_state,', line):
|
|
||||||
dumpfile.write(line.replace(
|
|
||||||
'>>,<<"pubsub.' + old_hostname + '">>,<<',
|
|
||||||
'>>,<<"pubsub.' + new_hostname + '">>,<<'))
|
|
||||||
elif re.match(r'\s*{pubsub_node,', line):
|
|
||||||
dumpfile.write(line.replace(
|
|
||||||
',{<<"pubsub.' + old_hostname + '">>,<<',
|
|
||||||
',{<<"pubsub.' + new_hostname + '">>,<<').replace(
|
|
||||||
'>>,<<"/home/' + old_hostname + '">>},',
|
|
||||||
'>>,<<"/home/' + new_hostname + '">>},'))
|
|
||||||
in_pubsub_node = True
|
|
||||||
else:
|
|
||||||
dumpfile.write(line)
|
|
||||||
|
|
||||||
subprocess.call(['service', 'ejabberd', 'restart'])
|
# restore backup database
|
||||||
|
if os.path.exists(EJABBERD_BACKUP_NEW):
|
||||||
# load backup database
|
|
||||||
if os.path.exists(EJABBERD_BACKUP):
|
|
||||||
try:
|
try:
|
||||||
subprocess.check_output(['ejabberdctl',
|
subprocess.check_output(['ejabberdctl',
|
||||||
'load',
|
'restore',
|
||||||
EJABBERD_BACKUP])
|
EJABBERD_BACKUP_NEW])
|
||||||
os.remove(EJABBERD_BACKUP)
|
os.remove(EJABBERD_BACKUP_NEW)
|
||||||
except subprocess.CalledProcessError as err:
|
except subprocess.CalledProcessError as err:
|
||||||
print('Failed to load ejabberd backup database: %s', err)
|
print('Failed to restore ejabberd backup database: %s', err)
|
||||||
else:
|
else:
|
||||||
print('Could not load ejabberd backup database: %s not found'
|
print('Could not load ejabberd backup database: %s not found'
|
||||||
% EJABBERD_BACKUP)
|
% EJABBERD_BACKUP_NEW)
|
||||||
|
|
||||||
|
|
||||||
def subcommand_register(arguments):
|
def subcommand_register(arguments):
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user