From e6f3a99269927a17829977dfa9682eb22827eae6 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Mon, 18 Feb 2019 17:44:09 +0100 Subject: [PATCH] Change binding from service_regen_conf to tools_regen_conf --- debian/postinst | 2 +- locales/en.json | 1 + src/yunohost/backup.py | 4 ++-- src/yunohost/certificate.py | 7 +++--- ...0007_ssh_conf_managed_by_yunohost_step1.py | 6 ++--- ...0008_ssh_conf_managed_by_yunohost_step2.py | 6 ++--- src/yunohost/domain.py | 6 ++--- src/yunohost/service.py | 13 +++++++++++ src/yunohost/tools.py | 22 ++++++++++++------- 9 files changed, 44 insertions(+), 23 deletions(-) diff --git a/debian/postinst b/debian/postinst index df7112b9d..83220ae0b 100644 --- a/debian/postinst +++ b/debian/postinst @@ -12,7 +12,7 @@ do_configure() { bash /usr/share/yunohost/hooks/conf_regen/15-nginx init else echo "Regenerating configuration, this might take a while..." - yunohost service regen-conf --output-as none + yunohost tools regen-conf --output-as none echo "Launching migrations.." yunohost tools migrations migrate --auto diff --git a/locales/en.json b/locales/en.json index 34517a036..5ab2a749b 100644 --- a/locales/en.json +++ b/locales/en.json @@ -443,6 +443,7 @@ "service_enable_failed": "Unable to enable service '{service:s}'\n\nRecent service logs:{logs:s}", "service_enabled": "The service '{service:s}' has been enabled", "service_no_log": "No log to display for service '{service:s}'", + "service_regen_conf_is_deprecated": "'yunohost service regen-conf' is depracted! Please use 'yunohost tools regen-conf' instead.", "service_remove_failed": "Unable to remove service '{service:s}'", "service_removed": "The service '{service:s}' has been removed", "service_reload_failed": "Unable to reload service '{service:s}'\n\nRecent service logs:{logs:s}", diff --git a/src/yunohost/backup.py b/src/yunohost/backup.py index ed7799fc1..9f48700a2 100644 --- a/src/yunohost/backup.py +++ b/src/yunohost/backup.py @@ -50,7 +50,7 @@ from yunohost.hook import ( ) from yunohost.monitor import binary_to_human from yunohost.tools import tools_postinstall -from yunohost.service import service_regen_conf +from yunohost.regenconf import regen_conf from yunohost.log import OperationLogger from functools import reduce @@ -1191,7 +1191,7 @@ class RestoreManager(): else: operation_logger.success() - service_regen_conf() + regen_conf() def _restore_apps(self): """Restore all apps targeted""" diff --git a/src/yunohost/certificate.py b/src/yunohost/certificate.py index 855910b8a..d7e8c0157 100644 --- a/src/yunohost/certificate.py +++ b/src/yunohost/certificate.py @@ -43,7 +43,8 @@ from yunohost.utils.network import get_public_ip from moulinette import m18n from yunohost.app import app_ssowatconf -from yunohost.service import _run_service_command, service_regen_conf +from yunohost.service import _run_service_command +from yunohost.regenconf import regen_conf from yunohost.log import OperationLogger logger = getActionLogger('yunohost.certmanager') @@ -806,7 +807,7 @@ def _enable_certificate(domain, new_cert_folder): if os.path.isfile('/etc/yunohost/installed'): # regen nginx conf to be sure it integrates OCSP Stapling # (We don't do this yet if postinstall is not finished yet) - service_regen_conf(names=['nginx']) + regen_conf(names=['nginx']) _run_service_command("reload", "nginx") @@ -924,7 +925,7 @@ def _regen_dnsmasq_if_needed(): break if do_regen: - service_regen_conf(["dnsmasq"]) + regen_conf(["dnsmasq"]) def _name_self_CA(): diff --git a/src/yunohost/data_migrations/0007_ssh_conf_managed_by_yunohost_step1.py b/src/yunohost/data_migrations/0007_ssh_conf_managed_by_yunohost_step1.py index 080cc0163..39a7d34e3 100644 --- a/src/yunohost/data_migrations/0007_ssh_conf_managed_by_yunohost_step1.py +++ b/src/yunohost/data_migrations/0007_ssh_conf_managed_by_yunohost_step1.py @@ -8,10 +8,10 @@ from moulinette.utils.log import getActionLogger from moulinette.utils.filesystem import mkdir, rm from yunohost.tools import Migration -from yunohost.service import service_regen_conf, \ - _get_conf_hashes, \ +from yunohost.service import _get_conf_hashes, \ _calculate_hash, \ _run_service_command +from yunohost.regen_conf import regen_conf from yunohost.settings import settings_set from yunohost.utils.error import YunohostError @@ -64,7 +64,7 @@ class MyMigration(Migration): if os.path.exists('/etc/yunohost/from_script'): rm('/etc/yunohost/from_script') copyfile(SSHD_CONF, '/etc/ssh/sshd_config.bkp') - service_regen_conf(names=['ssh'], force=True) + regen_conf(names=['ssh'], force=True) copyfile('/etc/ssh/sshd_config.bkp', SSHD_CONF) # Restart ssh and backward if it fail diff --git a/src/yunohost/data_migrations/0008_ssh_conf_managed_by_yunohost_step2.py b/src/yunohost/data_migrations/0008_ssh_conf_managed_by_yunohost_step2.py index 0976f1354..fce44298d 100644 --- a/src/yunohost/data_migrations/0008_ssh_conf_managed_by_yunohost_step2.py +++ b/src/yunohost/data_migrations/0008_ssh_conf_managed_by_yunohost_step2.py @@ -6,9 +6,9 @@ from moulinette.utils.log import getActionLogger from moulinette.utils.filesystem import chown from yunohost.tools import Migration -from yunohost.service import service_regen_conf, \ - _get_conf_hashes, \ +from yunohost.service import _get_conf_hashes, \ _calculate_hash +from yunohost.regenconf import regen_conf from yunohost.settings import settings_set, settings_get from yunohost.utils.error import YunohostError from yunohost.backup import ARCHIVES_PATH @@ -36,7 +36,7 @@ class MyMigration(Migration): def migrate(self): settings_set("service.ssh.allow_deprecated_dsa_hostkey", False) - service_regen_conf(names=['ssh'], force=True) + regen_conf(names=['ssh'], force=True) # Update local archives folder permissions, so that # admin can scp archives out of the server diff --git a/src/yunohost/domain.py b/src/yunohost/domain.py index 3d46691f8..54ed81dfb 100644 --- a/src/yunohost/domain.py +++ b/src/yunohost/domain.py @@ -34,7 +34,7 @@ from moulinette.utils.log import getActionLogger import yunohost.certificate -from yunohost.service import service_regen_conf +from yunohost.regenconf import regen_conf from yunohost.utils.network import get_public_ip from yunohost.log import is_unit_operation @@ -111,7 +111,7 @@ def domain_add(operation_logger, auth, domain, dyndns=False): # Don't regen these conf if we're still in postinstall if os.path.exists('/etc/yunohost/installed'): - service_regen_conf(names=['nginx', 'metronome', 'dnsmasq', 'postfix', 'rspamd']) + regen_conf(names=['nginx', 'metronome', 'dnsmasq', 'postfix', 'rspamd']) app_ssowatconf(auth) except Exception: @@ -164,7 +164,7 @@ def domain_remove(operation_logger, auth, domain, force=False): else: raise YunohostError('domain_deletion_failed') - service_regen_conf(names=['nginx', 'metronome', 'dnsmasq', 'postfix']) + regen_conf(names=['nginx', 'metronome', 'dnsmasq', 'postfix']) app_ssowatconf(auth) hook_callback('post_domain_remove', args=[domain]) diff --git a/src/yunohost/service.py b/src/yunohost/service.py index ab0e791d8..d088f0029 100644 --- a/src/yunohost/service.py +++ b/src/yunohost/service.py @@ -410,6 +410,19 @@ def service_log(name, number=50): return result +def service_regen_conf(names=[], with_diff=False, force=False, dry_run=False, + list_pending=False): + + services = _get_services() + for name in names: + if name not in services: + raise YunohostError('service_unknown', service=service) + + logger.warning(m18n.n("service_regen_conf_is_deprecated")) + + return regen_conf(names, with_diff, force, dry_run, list_pending) + + def _run_service_command(action, service): """ Run services management command (start, stop, enable, disable, restart, reload) diff --git a/src/yunohost/tools.py b/src/yunohost/tools.py index b2fbf380c..deec0746f 100644 --- a/src/yunohost/tools.py +++ b/src/yunohost/tools.py @@ -47,7 +47,8 @@ from yunohost.app import app_fetchlist, app_info, app_upgrade, app_ssowatconf, a from yunohost.domain import domain_add, domain_list, _get_maindomain, _set_maindomain from yunohost.dyndns import _dyndns_available, _dyndns_provides from yunohost.firewall import firewall_upnp -from yunohost.service import service_status, service_regen_conf, service_log, service_start, service_enable +from yunohost.service import service_status, service_log, service_start, service_enable +from yunohost.regenconf import regen_conf from yunohost.monitor import monitor_disk, monitor_system from yunohost.utils.packages import ynh_packages_version from yunohost.utils.network import get_public_ip @@ -207,7 +208,7 @@ def tools_maindomain(operation_logger, auth, new_domain=None): # Regen configurations try: with open('/etc/yunohost/installed', 'r'): - service_regen_conf() + regen_conf() except IOError: pass @@ -325,7 +326,7 @@ def tools_postinstall(operation_logger, domain, password, ignore_dyndns=False, operation_logger.start() logger.info(m18n.n('yunohost_installing')) - service_regen_conf(['nslcd', 'nsswitch'], force=True) + regen_conf(['nslcd', 'nsswitch'], force=True) # Initialize LDAP for YunoHost # TODO: Improve this part by integrate ldapinit into conf_regen hook @@ -376,7 +377,7 @@ def tools_postinstall(operation_logger, domain, password, ignore_dyndns=False, os.system('chmod 644 /etc/ssowat/conf.json.persistent') # Create SSL CA - service_regen_conf(['ssl'], force=True) + regen_conf(['ssl'], force=True) ssl_dir = '/usr/share/yunohost/yunohost-config/ssl/yunoCA' # (Update the serial so that it's specific to this very instance) os.system("openssl rand -hex 19 > %s/serial" % ssl_dir) @@ -405,7 +406,7 @@ def tools_postinstall(operation_logger, domain, password, ignore_dyndns=False, logger.success(m18n.n('yunohost_ca_creation_success')) # New domain config - service_regen_conf(['nsswitch'], force=True) + regen_conf(['nsswitch'], force=True) domain_add(auth, domain, dyndns) tools_maindomain(auth, domain) @@ -433,7 +434,7 @@ def tools_postinstall(operation_logger, domain, password, ignore_dyndns=False, service_enable("yunohost-firewall") service_start("yunohost-firewall") - service_regen_conf(force=True) + regen_conf(force=True) # Restore original ssh conf, as chosen by the # admin during the initial install @@ -450,13 +451,18 @@ def tools_postinstall(operation_logger, domain, password, ignore_dyndns=False, else: # We need to explicitly ask the regen conf to regen ssh # (by default, i.e. first argument = None, it won't because it's too touchy) - service_regen_conf(names=["ssh"], force=True) + regen_conf(names=["ssh"], force=True) logger.success(m18n.n('yunohost_configured')) logger.warning(m18n.n('recommend_to_add_first_user')) +def tools_regen_conf(names=[], with_diff=False, force=False, dry_run=False, + list_pending=False): + return regen_conf(names, with_diff, force, dry_run, list_pending) + + def tools_update(ignore_apps=False, ignore_packages=False): """ Update apps & package cache, then display changelog @@ -693,7 +699,7 @@ def tools_diagnosis(auth, private=False): # Domains diagnosis['private']['domains'] = domain_list(auth)['domains'] - diagnosis['private']['regen_conf'] = service_regen_conf(with_diff=True, dry_run=True) + diagnosis['private']['regen_conf'] = regen_conf(with_diff=True, dry_run=True) try: diagnosis['security'] = {