From 0c987909669b203b5d1ed20dd0ec77de4901daba Mon Sep 17 00:00:00 2001 From: Lars Kellogg-Stedman Date: Tue, 2 Jun 2015 14:06:28 -0400 Subject: [PATCH] detect systemd using sd_booted() semantics This patch replaces the distro-specific system check with a mechanism that matches what systemd uses to implement the sd_booted() method (http://www.freedesktop.org/software/systemd/man/sd_booted.html). --- cloudinit/distros/__init__.py | 8 ++++++++ cloudinit/distros/rhel.py | 8 -------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/cloudinit/distros/__init__.py b/cloudinit/distros/__init__.py index e0cce67..8a94786 100644 --- a/cloudinit/distros/__init__.py +++ b/cloudinit/distros/__init__.py @@ -27,6 +27,7 @@ from six import StringIO import abc import os import re +import stat from cloudinit import importer from cloudinit import log as logging @@ -89,6 +90,13 @@ class Distro(object): self._write_hostname(writeable_hostname, self.hostname_conf_fn) self._apply_hostname(writeable_hostname) + def uses_systemd(self): + try: + res = os.lstat('/run/systemd/system') + return stat.S_ISDIR(res.st_mode) + except: + return False + @abc.abstractmethod def package_command(self, cmd, args=None, pkgs=None): raise NotImplementedError() diff --git a/cloudinit/distros/rhel.py b/cloudinit/distros/rhel.py index 30c805a..812e700 100644 --- a/cloudinit/distros/rhel.py +++ b/cloudinit/distros/rhel.py @@ -111,14 +111,6 @@ class Distro(distros.Distro): rhel_util.update_sysconfig_file(self.network_conf_fn, net_cfg) return dev_names - def uses_systemd(self): - # Fedora 18 and RHEL 7 were the first adopters in their series - (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): if self.uses_systemd(): if not out_fn: -- 2.4.0