[enh] Set main domain as hostname (#219)

This commit is contained in:
Alexandre Aubin 2017-02-13 16:07:09 +01:00 committed by GitHub
parent 035100d6db
commit 1d561123b6
2 changed files with 23 additions and 0 deletions

View file

@ -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",

View file

@ -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: