mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Rename monit status function to prevent override in runtime (#30702)
Fixes #30367
This commit is contained in:
parent
1faa0a7c60
commit
24f8a35258
1 changed files with 6 additions and 6 deletions
|
@ -100,7 +100,7 @@ def main():
|
|||
else:
|
||||
return ''
|
||||
|
||||
def status():
|
||||
def get_status():
|
||||
"""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)
|
||||
for line in out.split('\n'):
|
||||
|
@ -116,14 +116,14 @@ def main():
|
|||
def run_command(command):
|
||||
"""Runs a monit command, and returns the new status."""
|
||||
module.run_command('%s %s %s' % (MONIT, command, name), check_rc=True)
|
||||
return status()
|
||||
return get_status()
|
||||
|
||||
def wait_for_monit_to_stop_pending():
|
||||
"""Fails this run if there is no status or it's pending/initializing for timeout"""
|
||||
timeout_time = time.time() + timeout
|
||||
sleep_time = 5
|
||||
|
||||
running_status = status()
|
||||
running_status = get_status()
|
||||
while running_status == '' or 'pending' in running_status or 'initializing' in running_status:
|
||||
if time.time() >= timeout_time:
|
||||
module.fail_json(
|
||||
|
@ -134,7 +134,7 @@ def main():
|
|||
)
|
||||
|
||||
time.sleep(sleep_time)
|
||||
running_status = status()
|
||||
running_status = get_status()
|
||||
|
||||
MONIT_MAJOR_VERSION, MONIT_MINOR_VERSION = monit_version()
|
||||
|
||||
|
@ -149,7 +149,7 @@ def main():
|
|||
wait_for_monit_to_stop_pending()
|
||||
module.exit_json(changed=True, name=name, state=state)
|
||||
|
||||
present = status() != ''
|
||||
present = get_status() != ''
|
||||
|
||||
if not present and not state == 'present':
|
||||
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)
|
||||
|
||||
wait_for_monit_to_stop_pending()
|
||||
running = 'running' in status()
|
||||
running = 'running' in get_status()
|
||||
|
||||
if running and state in ['started', 'monitored']:
|
||||
module.exit_json(changed=False, name=name, state=state)
|
||||
|
|
Loading…
Reference in a new issue