Skip to content

Fix checking for service started status on Debian#6

Merged
mizzy merged 2 commits into
mizzy:masterfrom
benlangfeld:patch-1
Dec 4, 2013
Merged

Fix checking for service started status on Debian#6
mizzy merged 2 commits into
mizzy:masterfrom
benlangfeld:patch-1

Conversation

@benlangfeld

Copy link
Copy Markdown
Contributor

service SERVICE_NAME status should return a 0 exit code when running, or non-zero when not running. Piping into grep swallows this, and serves no apparent purpose. This results in services always appearing running as long as the command outputs something including 'running' to stdout, including strings like 'SERVICE_NAME is not running'.

`service SERVICE_NAME status` should return a 0 exit code when running, or non-zero when not running. Piping into grep swallows this, and serves no apparent purpose. This results in services *always* appearing running as long as the command outputs something including 'running' to stdout, including strings like 'SERVICE_NAME is not running'.
@mizzy

mizzy commented Dec 3, 2013

Copy link
Copy Markdown
Owner

Upstart base services return exit code 0 even if they are stopped.

For example,

$ service mysql status
mysql stop/waiting

$ echo $?
0

So you cannot know whether service is running or not only with exit code.

Please see mizzy/serverspec#130

@mizzy mizzy closed this Dec 3, 2013
@benlangfeld

Copy link
Copy Markdown
Contributor Author

So what happens when using SysV, which is what Debian still uses (not Ubuntu)? This isn't resolved, I'd appreciate the issue being left open until we figure out how to fix this since it's a real bug.

@mizzy

mizzy commented Dec 3, 2013

Copy link
Copy Markdown
Owner

OK, I will reopen this issue.

@mizzy mizzy reopened this Dec 3, 2013
@mizzy

mizzy commented Dec 3, 2013

Copy link
Copy Markdown
Owner

I don't use Debian, so I don't know the detail of this problem.But removing the lines breaks the compatibility, so please fix it by another way.

@benlangfeld

Copy link
Copy Markdown
Contributor Author

I guess if we can assume Ubuntu is always Upstart and Debian is always SysV, we could implement a Ubuntu provider and move this there... Does that sound like an acceptable solution? @bklang, thoughts?

Upstart does not return non-zero when a service is not running, so must grep for 'running'. On debian, this hides services that are not running but which log something like "not running".
@benlangfeld

Copy link
Copy Markdown
Contributor Author

How does that solution look?

@mizzy

mizzy commented Dec 4, 2013

Copy link
Copy Markdown
Owner

Thanks! It seems good to me.

mizzy added a commit that referenced this pull request Dec 4, 2013
Fix checking for service started status on Debian
@mizzy mizzy merged commit 0fbbee3 into mizzy:master Dec 4, 2013
@mizzy

mizzy commented Dec 4, 2013

Copy link
Copy Markdown
Owner

I've just released as v0.0.7. Thanks!

mizzy added a commit to mizzy/serverspec that referenced this pull request Dec 4, 2013
@martinb3

Copy link
Copy Markdown
Contributor

Not all init scripts return 'running,' so this doesn't work for all cases.

@mizzy

mizzy commented Jul 29, 2014

Copy link
Copy Markdown
Owner

Patches are welcome.

@jorhett

jorhett commented Mar 30, 2016

Copy link
Copy Markdown

Easy fix: also check for "done", as init scripts are supposed to use the lsb functions, and check out line 118 here http://apt-browse.org/browse/ubuntu/trusty/main/all/lsb-base/4.1%2BDebian11ubuntu6/file/lib/lsb/init-functions.d/50-ubuntu-logging

chaaaaarlotte pushed a commit to chaaaaarlotte/specinfra that referenced this pull request Dec 28, 2022
Add some dependencies to gemspec
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants