Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Service module outputting extra data #625

Merged
merged 1 commit into from
Jul 19, 2012
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 11 additions & 22 deletions library/service
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ def _find_binaries():

def _get_service_status(name):
rc, status_stdout, status_stderr = _run("%s %s status" % (SERVICE, name))
status = status_stdout + status_stderr

# set the running state to None because we don't know it yet
running = None
Expand All @@ -99,16 +98,18 @@ def _get_service_status(name):
# if the job status is still not known check it by status output keywords
if running == None:
# first tranform the status output that could irritate keyword matching
cleaned_status_stdout = status_stdout.lower().replace(name.lower(),'')
if cleaned_status_stdout.find("stop") != -1:
cleanout = status_stdout.lower().replace(name.lower(), '')
if "stop" in cleanout:
running = False
elif cleaned_status_stdout.find("run") != -1 and cleaned_status_stdout.find("not") != -1:
elif "run" in cleanout and "not" in cleanout:
running = False
elif cleaned_status_stdout.find("run") != -1 and cleaned_status_stdout.find("not") == -1:
elif "run" in cleanout and "not" not in cleanout:
running = True
elif cleaned_status_stdout.find("start") != -1 and cleaned_status_stdout.find("not") == -1:
elif "start" in cleanout and "not" not in cleanout:
running = True
elif 'could not access pid file' in cleaned_status_stdout:
elif 'could not access pid file' in cleanout:
running = False
elif 'is dead and pid file exists' in cleanout:
running = False

# if the job status is still not known check it by special conditions
Expand Down Expand Up @@ -205,8 +206,9 @@ if state or enable:
print json.dumps({
"failed" : True,
"msg" : "failed determining the current service state => state stays unchanged",
"changed": False
})
print >> sys.stderr, out + err
sys.exit(1)
elif state:
# a state change command has been requested

Expand Down Expand Up @@ -244,10 +246,9 @@ if state or enable:
if rc != 0:

print json.dumps({
"failed" : 1,
"failed" : True,
"rc" : rc,
})
print >> sys.stderr, out + err
sys.exit(1)


Expand All @@ -260,20 +261,8 @@ if state or enable:
if list_items and list_items in [ 'status' ]:
result['status'] = stdout
print json.dumps(result)


elif list_items is not None:

# solo list=status mode, don't change anything, just return
# suitable for /usr/bin/ansible usage or API, playbooks
# not so much

print json.dumps({
"status" : status
})

else:

print json.dumps(dict(failed=True, msg="expected state or list parameters"))


Expand Down