diff options
author | Scott Moser <smoser@ubuntu.com> | 2015-05-15 10:53:10 -0400 |
---|---|---|
committer | Scott Moser <smoser@ubuntu.com> | 2015-05-15 10:53:10 -0400 |
commit | 02da8491a11caf783e952a964da5bc90a618d46f (patch) | |
tree | bebe4edd8132fccf27a49d2d03c87a48d61b14f5 | |
parent | 74023961b70a178039ecf10f68745f6927113978 (diff) | |
parent | 57c3365ec8310ff09cafa4c0f3fbdfb48c787e18 (diff) | |
download | vyos-cloud-init-02da8491a11caf783e952a964da5bc90a618d46f.tar.gz vyos-cloud-init-02da8491a11caf783e952a964da5bc90a618d46f.zip |
detect that CentOS 7 uses systemd, write previous-hostname in that case.
Also, on RHEL-type systems using systemd,
/var/lib/cloud/data/previous-hostname would never get created (because
rather then write to files, it was executing hostnamectl)
-rw-r--r-- | ChangeLog | 1 | ||||
-rw-r--r-- | cloudinit/distros/rhel.py | 11 |
2 files changed, 10 insertions, 2 deletions
@@ -39,6 +39,7 @@ [Surojit Pathak] - Azure: do not re-set hostname if user has changed it (LP: #1375252) - Fix exception when running with no arguments on Python 3. [Daniel Watkins] + - Centos: detect/expect use of systemd on centos 7. [Brian Rak] 0.7.6: - open 0.7.6 - Enable vendordata on CloudSigma datasource (LP: #1303986) diff --git a/cloudinit/distros/rhel.py b/cloudinit/distros/rhel.py index 7408989c..eec17c61 100644 --- a/cloudinit/distros/rhel.py +++ b/cloudinit/distros/rhel.py @@ -116,6 +116,7 @@ class Distro(distros.Distro): (dist, vers) = util.system_info()['dist'][:2] major = (int)(vers.split('.')[0]) return ((dist.startswith('Red Hat Enterprise Linux') and major >= 7) + or (dist.startswith('CentOS Linux') and major >= 7) or (dist.startswith('Fedora') and major >= 18)) def apply_locale(self, locale, out_fn=None): @@ -132,7 +133,11 @@ class Distro(distros.Distro): rhel_util.update_sysconfig_file(out_fn, locale_cfg) def _write_hostname(self, hostname, out_fn): - if self.uses_systemd(): + # systemd will never update previous-hostname for us, so + # we need to do it ourselves + if self.uses_systemd() and out_fn.endswith('/previous-hostname'): + util.write_file(out_fn, hostname) + elif self.uses_systemd(): util.subp(['hostnamectl', 'set-hostname', str(hostname)]) else: host_cfg = { @@ -155,7 +160,9 @@ class Distro(distros.Distro): return (host_fn, self._read_hostname(host_fn)) def _read_hostname(self, filename, default=None): - if self.uses_systemd(): + if self.uses_systemd() and filename.endswith('/previous-hostname'): + return util.load_file(filename).strip() + elif self.uses_systemd(): (out, _err) = util.subp(['hostname']) if len(out): return out |