|
|
@ -272,44 +272,41 @@ def main():
|
|
|
|
if rc != 0:
|
|
|
|
if rc != 0:
|
|
|
|
module.fail_json(msg='failure %d during daemon-reload: %s' % (rc, err))
|
|
|
|
module.fail_json(msg='failure %d during daemon-reload: %s' % (rc, err))
|
|
|
|
|
|
|
|
|
|
|
|
# check service data
|
|
|
|
|
|
|
|
(rc, out, err) = module.run_command("%s show '%s'" % (systemctl, unit))
|
|
|
|
|
|
|
|
if rc != 0:
|
|
|
|
|
|
|
|
module.fail_json(msg='failure %d running systemctl show for %r: %s' % (rc, unit, err))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
found = False
|
|
|
|
found = False
|
|
|
|
is_initd = sysv_exists(unit)
|
|
|
|
is_initd = sysv_exists(unit)
|
|
|
|
is_systemd = False
|
|
|
|
is_systemd = False
|
|
|
|
|
|
|
|
|
|
|
|
# load return of systemctl show into dictionary for easy access and return
|
|
|
|
# check service data, cannot error out on rc as it changes across versions, assume not found
|
|
|
|
multival = []
|
|
|
|
(rc, out, err) = module.run_command("%s show '%s'" % (systemctl, unit))
|
|
|
|
if out:
|
|
|
|
if rc == 0:
|
|
|
|
k = None
|
|
|
|
# load return of systemctl show into dictionary for easy access and return
|
|
|
|
for line in to_native(out).split('\n'): # systemd can have multiline values delimited with {}
|
|
|
|
multival = []
|
|
|
|
if line.strip():
|
|
|
|
if out:
|
|
|
|
if k is None:
|
|
|
|
k = None
|
|
|
|
if '=' in line:
|
|
|
|
for line in to_native(out).split('\n'): # systemd can have multiline values delimited with {}
|
|
|
|
k,v = line.split('=', 1)
|
|
|
|
if line.strip():
|
|
|
|
if v.lstrip().startswith('{'):
|
|
|
|
if k is None:
|
|
|
|
if not v.rstrip().endswith('}'):
|
|
|
|
if '=' in line:
|
|
|
|
multival.append(line)
|
|
|
|
k,v = line.split('=', 1)
|
|
|
|
continue
|
|
|
|
if v.lstrip().startswith('{'):
|
|
|
|
result['status'][k] = v.strip()
|
|
|
|
if not v.rstrip().endswith('}'):
|
|
|
|
k = None
|
|
|
|
multival.append(line)
|
|
|
|
else:
|
|
|
|
continue
|
|
|
|
if line.rstrip().endswith('}'):
|
|
|
|
result['status'][k] = v.strip()
|
|
|
|
result['status'][k] = '\n'.join(multival).strip()
|
|
|
|
k = None
|
|
|
|
multival = []
|
|
|
|
|
|
|
|
k = None
|
|
|
|
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
multival.append(line)
|
|
|
|
if line.rstrip().endswith('}'):
|
|
|
|
|
|
|
|
result['status'][k] = '\n'.join(multival).strip()
|
|
|
|
is_systemd = 'LoadState' in result['status'] and result['status']['LoadState'] != 'not-found'
|
|
|
|
multival = []
|
|
|
|
|
|
|
|
k = None
|
|
|
|
# Check for loading error
|
|
|
|
else:
|
|
|
|
if is_systemd and 'LoadError' in result['status']:
|
|
|
|
multival.append(line)
|
|
|
|
module.fail_json(msg="Error loading unit file '%s': %s" % (unit, result['status']['LoadError']))
|
|
|
|
|
|
|
|
|
|
|
|
is_systemd = 'LoadState' in result['status'] and result['status']['LoadState'] != 'not-found'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Check for loading error
|
|
|
|
|
|
|
|
if is_systemd and 'LoadError' in result['status']:
|
|
|
|
|
|
|
|
module.fail_json(msg="Error loading unit file '%s': %s" % (unit, result['status']['LoadError']))
|
|
|
|
|
|
|
|
|
|
|
|
# Does service exist?
|
|
|
|
# Does service exist?
|
|
|
|
found = is_systemd or is_initd
|
|
|
|
found = is_systemd or is_initd
|
|
|
|