mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-07 22:02:50 +00:00
Rename monit status function to prevent override in runtime (#30702)
Fixes #30367
This commit is contained in:
@@ -100,7 +100,7 @@ def main():
|
|||||||
else:
|
else:
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
def status():
|
def get_status():
|
||||||
"""Return the status of the process in monit, or the empty string if not present."""
|
"""Return the status of the process in monit, or the empty string if not present."""
|
||||||
rc, out, err = module.run_command('%s %s' % (MONIT, SUMMARY_COMMAND), check_rc=True)
|
rc, out, err = module.run_command('%s %s' % (MONIT, SUMMARY_COMMAND), check_rc=True)
|
||||||
for line in out.split('\n'):
|
for line in out.split('\n'):
|
||||||
@@ -116,14 +116,14 @@ def main():
|
|||||||
def run_command(command):
|
def run_command(command):
|
||||||
"""Runs a monit command, and returns the new status."""
|
"""Runs a monit command, and returns the new status."""
|
||||||
module.run_command('%s %s %s' % (MONIT, command, name), check_rc=True)
|
module.run_command('%s %s %s' % (MONIT, command, name), check_rc=True)
|
||||||
return status()
|
return get_status()
|
||||||
|
|
||||||
def wait_for_monit_to_stop_pending():
|
def wait_for_monit_to_stop_pending():
|
||||||
"""Fails this run if there is no status or it's pending/initializing for timeout"""
|
"""Fails this run if there is no status or it's pending/initializing for timeout"""
|
||||||
timeout_time = time.time() + timeout
|
timeout_time = time.time() + timeout
|
||||||
sleep_time = 5
|
sleep_time = 5
|
||||||
|
|
||||||
running_status = status()
|
running_status = get_status()
|
||||||
while running_status == '' or 'pending' in running_status or 'initializing' in running_status:
|
while running_status == '' or 'pending' in running_status or 'initializing' in running_status:
|
||||||
if time.time() >= timeout_time:
|
if time.time() >= timeout_time:
|
||||||
module.fail_json(
|
module.fail_json(
|
||||||
@@ -134,7 +134,7 @@ def main():
|
|||||||
)
|
)
|
||||||
|
|
||||||
time.sleep(sleep_time)
|
time.sleep(sleep_time)
|
||||||
running_status = status()
|
running_status = get_status()
|
||||||
|
|
||||||
MONIT_MAJOR_VERSION, MONIT_MINOR_VERSION = monit_version()
|
MONIT_MAJOR_VERSION, MONIT_MINOR_VERSION = monit_version()
|
||||||
|
|
||||||
@@ -149,7 +149,7 @@ def main():
|
|||||||
wait_for_monit_to_stop_pending()
|
wait_for_monit_to_stop_pending()
|
||||||
module.exit_json(changed=True, name=name, state=state)
|
module.exit_json(changed=True, name=name, state=state)
|
||||||
|
|
||||||
present = status() != ''
|
present = get_status() != ''
|
||||||
|
|
||||||
if not present and not state == 'present':
|
if not present and not state == 'present':
|
||||||
module.fail_json(msg='%s process not presently configured with monit' % name, name=name, state=state)
|
module.fail_json(msg='%s process not presently configured with monit' % name, name=name, state=state)
|
||||||
@@ -165,7 +165,7 @@ def main():
|
|||||||
module.exit_json(changed=False, name=name, state=state)
|
module.exit_json(changed=False, name=name, state=state)
|
||||||
|
|
||||||
wait_for_monit_to_stop_pending()
|
wait_for_monit_to_stop_pending()
|
||||||
running = 'running' in status()
|
running = 'running' in get_status()
|
||||||
|
|
||||||
if running and state in ['started', 'monitored']:
|
if running and state in ['started', 'monitored']:
|
||||||
module.exit_json(changed=False, name=name, state=state)
|
module.exit_json(changed=False, name=name, state=state)
|
||||||
|
|||||||
Reference in New Issue
Block a user