mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-01-21 07:55:00 +00:00
matrixsynapse: Perform a one time conversion to new config format
- This will allow us to remove the code needed for force upgrading. Upgrade code can be dropped after a while. - This will ensure that all our users have a single configuration format which will make future testing easier. - We can notify the users of a single overwrite now and be assured that in future, the overwrites of configuration will not happen. - We don't have to monitor for changes to configuration files in future version of the package. - Keep old configuration as a backup file and restore a pristine copy with --reinstall and --force-confmiss. Tests: - Install the app freshly. Configuration file is unchanged, new config snippets are created. App is running. - Install the app with code before new configuration changes. Notice that old configuration format is used. Then switch the code to a branch with current changes. Setup is automatically executed. The package is reinstalled. After re-installation, the main config file is restored. Configuration snippets exist. value of public registration and domain is preserved. Backup file exists with previous configuration contents. Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Tested-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
parent
f59fc5e33b
commit
893ecbed1b
@ -5,12 +5,14 @@ Configuration helper for Matrix-Synapse server.
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import pathlib
|
||||
|
||||
import yaml
|
||||
|
||||
from plinth import action_utils
|
||||
from plinth.modules.matrixsynapse import ORIG_CONF_PATH, STATIC_CONF_PATH, \
|
||||
LISTENERS_CONF_PATH, REGISTRATION_CONF_PATH
|
||||
from plinth.modules.matrixsynapse import (LISTENERS_CONF_PATH, ORIG_CONF_PATH,
|
||||
REGISTRATION_CONF_PATH,
|
||||
STATIC_CONF_PATH)
|
||||
|
||||
STATIC_CONFIG = {
|
||||
'max_upload_size':
|
||||
@ -47,6 +49,10 @@ def parse_arguments():
|
||||
'--domain-name',
|
||||
help='The domain name that will be used by Matrix Synapse')
|
||||
|
||||
subparsers.add_parser(
|
||||
'move-old-conf',
|
||||
help='Move old configuration file to backup before reinstall')
|
||||
|
||||
subparsers.required = True
|
||||
return parser.parse_args()
|
||||
|
||||
@ -110,6 +116,14 @@ def subcommand_public_registration(argument):
|
||||
action_utils.service_restart('matrix-synapse')
|
||||
|
||||
|
||||
def subcommand_move_old_conf(_arguments):
|
||||
"""Move old configuration to backup so it can be restored by reinstall."""
|
||||
conf_file = pathlib.Path(ORIG_CONF_PATH)
|
||||
if conf_file.exists():
|
||||
backup_file = conf_file.with_suffix(conf_file.suffix + '.fbx-bak')
|
||||
conf_file.replace(backup_file)
|
||||
|
||||
|
||||
def main():
|
||||
arguments = parse_arguments()
|
||||
sub_command = arguments.subcommand.replace('-', '_')
|
||||
|
||||
@ -18,11 +18,10 @@ from plinth.daemon import Daemon
|
||||
from plinth.modules.apache.components import Webserver
|
||||
from plinth.modules.firewall.components import Firewall
|
||||
from plinth.modules.letsencrypt.components import LetsEncrypt
|
||||
from plinth.utils import Version
|
||||
|
||||
from .manifest import backup, clients # noqa, pylint: disable=unused-import
|
||||
|
||||
version = 5
|
||||
version = 6
|
||||
|
||||
managed_services = ['matrix-synapse']
|
||||
|
||||
@ -111,31 +110,29 @@ class MatrixSynapseApp(app_module.App):
|
||||
def setup(helper, old_version=None):
|
||||
"""Install and configure the module."""
|
||||
helper.install(managed_packages)
|
||||
helper.call('post', actions.superuser_run, 'matrixsynapse',
|
||||
['post-install'])
|
||||
helper.call('post', app.enable)
|
||||
if old_version and old_version < 6:
|
||||
helper.call('post', upgrade, helper)
|
||||
else:
|
||||
helper.call('post', actions.superuser_run, 'matrixsynapse',
|
||||
['post-install'])
|
||||
|
||||
if not old_version:
|
||||
helper.call('post', app.enable)
|
||||
|
||||
app.get_component('letsencrypt-matrixsynapse').setup_certificates()
|
||||
|
||||
|
||||
def force_upgrade(helper, packages):
|
||||
"""Force upgrade matrix-synapse to resolve conffile prompt."""
|
||||
if 'matrix-synapse' not in packages:
|
||||
return False
|
||||
|
||||
# Allow any lower version to upgrade to 1.15.*
|
||||
package = packages['matrix-synapse']
|
||||
if Version(package['new_version']) > Version('1.16~'):
|
||||
return False
|
||||
|
||||
def upgrade(helper):
|
||||
"""Upgrade matrix-synapse configuration to avoid conffile prompt."""
|
||||
public_registration_status = get_public_registration_status()
|
||||
helper.install(['matrix-synapse'], force_configuration='new')
|
||||
actions.superuser_run('matrixsynapse', ['move-old-conf'])
|
||||
helper.install(['matrix-synapse'], force_configuration='new',
|
||||
reinstall=True, force_missing_configuration=True)
|
||||
actions.superuser_run('matrixsynapse', ['post-install'])
|
||||
if public_registration_status:
|
||||
actions.superuser_run('matrixsynapse',
|
||||
['public-registration', 'enable'])
|
||||
|
||||
return True
|
||||
|
||||
|
||||
def setup_domain(domain_name):
|
||||
"""Configure a domain name for matrixsynapse."""
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user