1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

improved logic when dealing with init scripts

This commit is contained in:
Brian Coca 2016-08-11 09:43:16 -04:00 committed by Matt Clay
parent 3c89a21e0c
commit ab3a87cc1a

View file

@ -309,9 +309,15 @@ def main():
(rc, out, err) = module.run_command("%s is-enabled '%s'" % (systemctl, unit)) (rc, out, err) = module.run_command("%s is-enabled '%s'" % (systemctl, unit))
# check systemctl result or if it is a init script # check systemctl result or if it is a init script
initscript = '/etc/init.d/' + unit if rc == 0:
if rc == 0 or (os.access(initscript, os.X_OK) and bool(glob.glob('/etc/rc?.d/S??' + unit))):
enabled = True enabled = True
elif rc == 1:
# Deals with init scripts
# if both init script and unit file exist stdout should have enabled/disabled, otherwise use rc entries
initscript = '/etc/init.d/' + unit
if os.path.exists(initscript) and os.access(initscript, os.X_OK) and \
(not out.startswith('disabled') or bool(glob.glob('/etc/rc?.d/S??' + unit))):
enabled = True
# default to current state # default to current state
result['enabled'] = enabled result['enabled'] = enabled