Merge pull request #24723 from rallytime/bp-20124

Back-port #20124 to 2015.5
This commit is contained in:
Thomas S Hatch 2015-06-17 09:43:20 -07:00
commit ac2851be55

View file

@ -1030,6 +1030,38 @@ def os_data():
grains['systemd']['version'] = systemd_info[0].split()[1]
grains['systemd']['features'] = systemd_info[1]
# Add init grain
grains['init'] = 'unknown'
try:
os.stat('/run/systemd/system')
grains['init'] = 'systemd'
except OSError:
with salt.utils.fopen('/proc/1/cmdline') as fhr:
init_cmdline = fhr.read().replace('\x00', ' ').split()
init_bin = salt.utils.which(init_cmdline[0])
supported_inits = ('upstart', 'sysvinit', 'systemd')
edge_len = max(len(x) for x in supported_inits) - 1
buf_size = __opts__['file_buffer_size']
try:
with open(init_bin, 'rb') as fp_:
buf = True
edge = ''
buf = fp_.read(buf_size).lower()
while buf:
buf = edge + buf
for item in supported_inits:
if item in buf:
grains['init'] = item
buf = ''
break
edge = buf[-edge_len:]
buf = fp_.read(buf_size).lower()
except (IOError, OSError) as exc:
log.error(
'Unable to read from init_bin ({0}): {1}'
.format(init_bin, exc)
)
# Add lsb grains on any distro with lsb-release
try:
import lsb_release