From 0ebbb83191273ca716ecaf1c128ece0705b84c82 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Mon, 18 Feb 2019 19:03:43 +0100 Subject: [PATCH] Add migration for services.yml on existing instance --- data/templates/yunohost/services.yml | 9 ++-- .../0009_decouple_regenconf_from_services.py | 42 +++++++++++++++++++ src/yunohost/regenconf.py | 12 ++++++ 3 files changed, 57 insertions(+), 6 deletions(-) create mode 100644 src/yunohost/data_migrations/0009_decouple_regenconf_from_services.py diff --git a/data/templates/yunohost/services.yml b/data/templates/yunohost/services.yml index 62509e1e9..0d79b182f 100644 --- a/data/templates/yunohost/services.yml +++ b/data/templates/yunohost/services.yml @@ -20,8 +20,6 @@ mysql: glances: {} ssh: log: /var/log/auth.log -ssl: - status: null metronome: log: [/var/log/metronome/metronome.log,/var/log/metronome/metronome.err] slapd: @@ -34,10 +32,9 @@ yunohost-firewall: need_lock: true nslcd: log: /var/log/syslog -nsswitch: - status: null -yunohost: - status: null +nsswitch: null +ssl: null +yunohost: null bind9: null tahoe-lafs: null memcached: null diff --git a/src/yunohost/data_migrations/0009_decouple_regenconf_from_services.py b/src/yunohost/data_migrations/0009_decouple_regenconf_from_services.py new file mode 100644 index 000000000..e65aadfdf --- /dev/null +++ b/src/yunohost/data_migrations/0009_decouple_regenconf_from_services.py @@ -0,0 +1,42 @@ +import os + +from moulinette import m18n +from moulinette.utils.log import getActionLogger + +from moulinette.utils.filesystem import read_file +from yunohost.service import _get_services, _save_services +from yunohost.regenconf import _update_conf_hashes + +from yunohost.tools import Migration + +logger = getActionLogger('yunohost.migration') + + +class MyMigration(Migration): + """ + Decouple the regen conf mechanism from the concept of services + """ + + def migrate(self): + + if "conffiles" not in read_file("/etc/yunohost/services.yml") \ + or os.path.exists("/etc/yunohost/regenconf.yml"): + logger.warning(m18n.n("migration_0009_not_needed")) + return + + # For all services + services = _get_services() + for service, infos in services.items(): + # If there are some conffiles (file hashes) + if "conffiles" in infos.keys(): + # Save them using the new regen conf thingy + _update_conf_hashes(service, infos["conffiles"]) + # And delete the old conffile key from the service infos + del services[service]["conffiles"] + + # (Actually save the modification of services) + _save_services(services) + + def backward(self): + + pass diff --git a/src/yunohost/regenconf.py b/src/yunohost/regenconf.py index 783b50c4a..3ea8ccb6d 100644 --- a/src/yunohost/regenconf.py +++ b/src/yunohost/regenconf.py @@ -31,6 +31,7 @@ from datetime import datetime from moulinette import m18n from moulinette.utils import log, filesystem +from moulinette.utils.filesystem import read_file from yunohost.utils.error import YunohostError from yunohost.log import is_unit_operation @@ -60,6 +61,17 @@ def regen_conf(operation_logger, names=[], with_diff=False, force=False, dry_run list_pending -- List pending configuration files and exit """ + + # Legacy code to automatically run the migration + # This is required because regen_conf is called before the migration call + # in debian's postinst script + if os.path.exists("/etc/yunohost/installed") \ + and ("conffiles" in read_file("/etc/yunohost/services.yml") \ + or not os.path.exists("/etc/yunohost/regenconf.yml")): + from yunohost.tools import _get_migration_by_name + migration = _get_migration_by_name("decouple_regenconf_from_services") + migration.migrate() + result = {} # Return the list of pending conf