running = False
if status_stdout.find("stopped") != -1 or rc == 3:
running = False
elif status_stdout.find("running") != -1 or rc == 0:
running = True
elif name == 'iptables' and status_stdout.find("ACCEPT") != -1:
# iptables status command output is lame
# TODO: lookup if we can use a return code for this instead?
running = TrueI've tested on Ubuntu 10.04 because we mainly use this release by now.Let me give you a few examples of the output of the service <servicename> status command.MySQL:
- Output in stopped state: mysql stop/waiting
- Return Code in stopped state: 0
- Output in started state: mysql start/running, process 20846
- Return Code in started state: 0
Apache2:
- Output in stopped state: Apache is NOT running.
- Return Code in stopped state: 1
- Output in started state: Apache is running (pid 21454).
- Return Code in started state: 0
The Problem here is, that the current service module always sees my Apache in the state running, even if it's not.Since Ubuntu is using two ways for their init scripts. The old init way and the new upstart.
Maybe it would be a better solution to check first if the service has an upstart script. (e.g. with initctl list)With upstart the service status output is standardized and you can check for the keywords.
The output of the old init scripts is just "free human text" and therefor not reliable for a keyword based check.
P.S.: sorry for the long post, but this topic is really important to me and i think it's a core function of ansible that's broken
running = False
if status_stdout.find("stopped") != -1 or rc == 3:
running = False
elif status_stdout.find("running") != -1 or rc == 0:
running = True
elif name == 'iptables' and status_stdout.find("ACCEPT") != -1:
# iptables status command output is lame
# TODO: lookup if we can use a return code for this instead?
running = TrueI've tested on Ubuntu 10.04 because we mainly use this release by now.Let me give you a few examples of the output of the service <servicename> status command.MySQL:
- Output in stopped state: mysql stop/waiting
Ok so it would return "running = False" in this case, which is correct.
- Return Code in stopped state: 0
- Output in started state: mysql start/running, process 20846
- Return Code in started state: 0
So the math above would find running first in the above logic and return running = True, which is ALSO correct.Apache2:
- Output in stopped state: Apache is NOT running.
- Return Code in stopped state: 1
- Output in started state: Apache is running (pid 21454).
- Return Code in started state: 0
The Problem here is, that the current service module always sees my Apache in the state running, even if it's not.Since Ubuntu is using two ways for their init scripts. The old init way and the new upstart.This means it the code could also make a check to make sure the string does not contain "not". Patches accepted, sounds like a trivial fix.
Maybe it would be a better solution to check first if the service has an upstart script. (e.g. with initctl list)With upstart the service status output is standardized and you can check for the keywords.Not sure this is necessary per the above.The output of the old init scripts is just "free human text" and therefor not reliable for a keyword based check.Yeah though I think the "not" is the only case we have had of this so far.P.S.: sorry for the long post, but this topic is really important to me and i think it's a core function of ansible that's brokenFWIW, you're the first one out of hundreds to mention it.Patch is pretty simple though. Send me a pull request.
Maybe I should just try it in a branch of my fork on github and you could review it when I'm done.Would that be ok for you?
Could you please test it on your systems?Tell me if you want to change something or if I should send you the pull request.