service_mgr: detect systemd, even offline (#66071)

* service_mgr: detect systemd, even offline

* service_mgr=systemd iff /sbin/init is symlink
This commit is contained in:
James Cassell 2020-02-04 17:32:36 -05:00 committed by GitHub
parent 4ac89b8ac7
commit 1bb94ec92f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 0 deletions

View file

@ -0,0 +1,3 @@
bugfixes:
- setup - service_mgr - detect systemd even if it isn't running, such as during
a container build

View file

@ -52,6 +52,16 @@ class ServiceMgrFactCollector(BaseFactCollector):
return True
return False
@staticmethod
def is_systemd_managed_offline(module):
# tools must be installed
if module.get_bin_path('systemctl'):
# check if /sbin/init is a symlink to systemd
# on SUSE, /sbin/init may be missing if systemd-sysvinit package is not installed.
if os.path.islink('/sbin/init') and os.path.basename(os.readlink('/sbin/init')) == 'systemd':
return True
return False
def collect(self, module=None, collected_facts=None):
facts_dict = {}
@ -129,6 +139,8 @@ class ServiceMgrFactCollector(BaseFactCollector):
service_mgr_name = 'upstart'
elif os.path.exists('/sbin/openrc'):
service_mgr_name = 'openrc'
elif self.is_systemd_managed_offline(module=module):
service_mgr_name = 'systemd'
elif os.path.exists('/etc/init.d/'):
service_mgr_name = 'sysvinit'