mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
add init system to default grains (resolve #20124)
This commit is contained in:
parent
3d33fe7676
commit
f353454327
1 changed files with 17 additions and 0 deletions
|
@ -1030,6 +1030,23 @@ def os_data():
|
|||
grains['systemd']['version'] = systemd_info[0].split()[1]
|
||||
grains['systemd']['features'] = systemd_info[1]
|
||||
|
||||
# Add init grain
|
||||
if os.path.isdir('/run/systemd/system'):
|
||||
grains['init'] = 'systemd'
|
||||
else:
|
||||
with salt.utils.fopen('/proc/1/cmdline') as fhr:
|
||||
init_cmdline = fhr.read().replace('\x00', ' ').split()
|
||||
init_bin = salt.utils.which(init_cmdline[0])
|
||||
strings_out = __salt__['cmd.run']('strings {0}'.format(init_bin))
|
||||
if 'upstart' in strings_out.lower():
|
||||
grains['init'] = 'upstart'
|
||||
elif 'sysvinit' in strings_out.lower():
|
||||
grains['init'] = 'sysvinit'
|
||||
elif 'systemd' in strings_out.lower():
|
||||
grains['init'] = 'systemd'
|
||||
else:
|
||||
grains['init'] = 'unknown'
|
||||
|
||||
# Add lsb grains on any distro with lsb-release
|
||||
try:
|
||||
import lsb_release
|
||||
|
|
Loading…
Add table
Reference in a new issue