From fe3ecd7a7d4c632c97003d99d79a4af9650a05f5 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Mon, 12 Aug 2019 17:25:17 +0200 Subject: [PATCH] c.f. issue #1136, don't fail miserably in case we can't change the hostname because that should be okay --- locales/en.json | 2 +- src/yunohost/tools.py | 19 ++++++------------- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/locales/en.json b/locales/en.json index 2c9a5a5c8..b45739149 100644 --- a/locales/en.json +++ b/locales/en.json @@ -174,7 +174,7 @@ "domain_dyndns_invalid": "Invalid domain to use with DynDNS", "domain_dyndns_root_unknown": "Unknown DynDNS root domain", "domain_exists": "Domain already exists", - "domain_hostname_failed": "Failed to set new hostname", + "domain_hostname_failed": "Failed to set new hostname. This might cause issue later (not sure about it... it might be fine).", "domain_uninstall_app_first": "One or more apps are installed on this domain. Please uninstall them before proceeding to domain removal", "domain_unknown": "Unknown domain", "domain_zone_exists": "DNS zone file already exists", diff --git a/src/yunohost/tools.py b/src/yunohost/tools.py index 5e14082b5..c63f1ed33 100644 --- a/src/yunohost/tools.py +++ b/src/yunohost/tools.py @@ -225,10 +225,6 @@ def _set_hostname(hostname, pretty_hostname=None): Change the machine hostname using hostnamectl """ - if _is_inside_container(): - logger.warning("You are inside a container and hostname cannot easily be changed") - return - if not pretty_hostname: pretty_hostname = "(YunoHost/%s)" % hostname @@ -252,26 +248,23 @@ def _set_hostname(hostname, pretty_hostname=None): if p.returncode != 0: logger.warning(command) logger.warning(out) - raise YunohostError('domain_hostname_failed') + logger.error(m18n.n('domain_hostname_failed')) else: logger.debug(out) -def _is_inside_container(): +def _detect_virt(): """ - Check if we're inside a container (i.e. LXC) - - Returns True or False + Returns the output of systemd-detect-virt (so e.g. 'none' or 'lxc' or ...) + You can check the man of the command to have a list of possible outputs... """ - # See https://www.2daygeek.com/check-linux-system-physical-virtual-machine-virtualization-technology/ - p = subprocess.Popen("sudo systemd-detect-virt".split(), + p = subprocess.Popen("systemd-detect-virt".split(), stdout=subprocess.PIPE, stderr=subprocess.STDOUT) out, _ = p.communicate() - container = ['lxc', 'lxd', 'docker'] - return out.split()[0] in container + return out.split()[0] @is_unit_operation()