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:
parent
4ac89b8ac7
commit
1bb94ec92f
2 changed files with 15 additions and 0 deletions
3
changelogs/fragments/service-mgr-systemd-offline.yml
Normal file
3
changelogs/fragments/service-mgr-systemd-offline.yml
Normal file
|
@ -0,0 +1,3 @@
|
|||
bugfixes:
|
||||
- setup - service_mgr - detect systemd even if it isn't running, such as during
|
||||
a container build
|
|
@ -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'
|
||||
|
||||
|
|
Loading…
Reference in a new issue