diff options
author | Daniil Baturin <daniil@baturin.org> | 2019-07-16 23:13:06 +0200 |
---|---|---|
committer | Daniil Baturin <daniil@baturin.org> | 2019-07-16 23:23:43 +0200 |
commit | 362775460d4e4d36e024d6d665a09cf9eadc724f (patch) | |
tree | 09e1d51735f82b955edde38ef976918c8d7e0444 /src/conf_mode/host_name.py | |
parent | 37a4d98daee93f57c19d3889e0e660c7645d6303 (diff) | |
download | vyos-1x-362775460d4e4d36e024d6d665a09cf9eadc724f.tar.gz vyos-1x-362775460d4e4d36e024d6d665a09cf9eadc724f.zip |
T1531: do not include FQDN in the hostname.
Diffstat (limited to 'src/conf_mode/host_name.py')
-rwxr-xr-x | src/conf_mode/host_name.py | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/src/conf_mode/host_name.py b/src/conf_mode/host_name.py index 651c1c392..ccf8ea175 100755 --- a/src/conf_mode/host_name.py +++ b/src/conf_mode/host_name.py @@ -25,6 +25,7 @@ import re import sys import copy import glob +import subprocess import argparse import jinja2 @@ -201,19 +202,27 @@ def apply(config): if config is None: return None - fqdn = config['hostname'] - if config['domain_name']: - fqdn += '.' + config['domain_name'] + # No domain name -- the Debian way. + hostname_new = config['hostname'] - os.system("hostnamectl set-hostname --static {0}".format(fqdn)) + # rsyslog runs into a race condition at boot time with systemd + # restart rsyslog only if the hostname changed. + hostname_old = subprocess.check_output(['hostnamectl', '--static']).decode().strip() + + os.system("hostnamectl set-hostname --static {0}".format(hostname_new)) # Restart services that use the hostname - os.system("systemctl restart rsyslog.service") + if hostname_new != hostname_old: + os.system("systemctl restart rsyslog.service") # If SNMP is running, restart it too if os.system("pgrep snmpd > /dev/null") == 0: os.system("systemctl restart snmpd.service") + # restart pdns if it is used + if os.system("/usr/bin/rec_control ping >/dev/null 2>&1") == 0: + os.system("/etc/init.d/pdns-recursor restart >/dev/null") + return None |