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

Minor fixes for openwrt_init for busybox ps and worthless exit codes

This commit is contained in:
Andrew Gaffney 2016-10-28 22:13:24 -06:00 committed by Matt Clay
parent e064fd3256
commit c238d3070a

View file

@ -78,10 +78,22 @@ import glob
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils._text import to_bytes, to_native
module = None
init_script = None
# ===============================
# Check if service is enabled
def is_enabled():
(rc, out, err) = module.run_command("%s enabled" % init_script)
if rc == 0:
return True
return False
# ===========================================
# Main control flow
def main():
global module, init_script
# init
module = AnsibleModule(
argument_spec = dict(
@ -111,11 +123,7 @@ def main():
# Enable/disable service startup at boot if requested
if module.params['enabled'] is not None:
# do we need to enable the service?
enabled = False
(rc, out, err) = module.run_command("%s enabled" % init_script)
if rc == 0:
enabled = True
enabled = is_enabled()
# default to current state
result['enabled'] = enabled
@ -130,7 +138,10 @@ def main():
if not module.check_mode:
(rc, out, err) = module.run_command("%s %s" % (init_script, action))
if rc != 0:
# openwrt init scripts can return a non-zero exit code on a successful 'enable'
# command if the init script doesn't contain a STOP value, so we ignore the exit
# code and explicitly check if the service is now in the desired state
if is_enabled() != module.params['enabled']:
module.fail_json(msg="Unable to %s service %s: %s" % (action, service, err))
result['enabled'] = not enabled
@ -143,7 +154,8 @@ def main():
# Find ps binary
psbin = module.get_bin_path('ps', True)
(rc, psout, pserr) = module.run_command('%s auxwww' % psbin)
# this should be busybox ps, so we only want/need to the 'w' option
(rc, psout, pserr) = module.run_command('%s w' % psbin)
# If rc is 0, set running as appropriate
if rc == 0:
lines = psout.split("\n")
@ -154,7 +166,6 @@ def main():
break
else:
(rc, out, err) = module.run_command("%s running" % init_script)
if rc == 0:
running = True