diff --git a/locales/en.json b/locales/en.json index 0880fdddd..fb1c58b43 100644 --- a/locales/en.json +++ b/locales/en.json @@ -81,6 +81,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_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 9d1d1c668..8470a7b27 100644 --- a/src/yunohost/tools.py +++ b/src/yunohost/tools.py @@ -163,6 +163,28 @@ def tools_maindomain(auth, new_domain=None): logger.warning("%s" % e, exc_info=1) raise MoulinetteError(errno.EPERM, m18n.n('maindomain_change_failed')) + # Set hostname + pretty_hostname = "(YunoHost/%s)" % new_domain + commands = [ + "sudo hostnamectl --static set-hostname".split() + [new_domain], + "sudo hostnamectl --transient set-hostname".split() + [new_domain], + "sudo hostnamectl --pretty set-hostname".split() + [pretty_hostname] + ] + + for command in commands: + p = subprocess.Popen(command, + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT) + + out, _ = p.communicate() + + if p.returncode != 0: + logger.warning(command) + logger.warning(out) + raise MoulinetteError(errno.EIO, m18n.n('domain_hostname_failed')) + else: + logger.info(out) + # Regen configurations try: with open('/etc/yunohost/installed', 'r') as f: