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

This fix hides the grep process from the first grep - which now notifies you if your process is not running. #33

Merged
merged 1 commit into from Apr 4, 2013
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion lib/serverspec/commands/base.rb
Expand Up @@ -36,7 +36,7 @@ def check_running service
end

def check_process process
"ps aux | grep -qw #{process}"
"ps aux | grep -w #{process} | grep -qv grep"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another way of achieving this is to replace the first letter of process by adding [] around it, doing grep -qw "[a]bc" instead of grep -qw "abc".

Actually, wouldn't it be better to use pgrep here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't sure pgrep was always available on all your supported platforms.
Is it?

On Wed, Apr 3, 2013 at 4:16 PM, Raphaël Pinson notifications@github.comwrote:

In lib/serverspec/commands/base.rb:

@@ -36,7 +36,7 @@ def check_running service
end

   def check_process process
  •    "ps aux | grep -qw #{process}"
    
  •    "ps aux | grep -w #{process} | grep -qv grep"
    

Another way of achieving this is to replace the first letter of processby adding
[] around it, doing grep -qw "[a]bc" instead of grep -qw "abc".

Actually, wouldn't it be better to use pgrep here?


Reply to this email directly or view it on GitHubhttps://github.com//pull/33/files#r3646338
.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

http://www.math.utah.edu/~beebe/unix/p/pgrep.html shows the support for it. Maybe it could be used when available, although that's not easy since all commands are launched through SSH.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I don't think pgrep will work for this reliably - here's what I
get:

root@solr-berkshelf:# pgrep jetty
root@solr-berkshelf:
# echo $?
1
root@solr-berkshelf:# ps aux | grep -w jetty | grep -qv grep
root@solr-berkshelf:
# echo $?
0
root@solr-berkshelf:~# ps aux | grep -w jetty | grep -v grep
jetty 12169 0.4 23.3 1543184 87252 ? Sl Apr03 1:12 /usr/bin/java -Dsolr.solr.home=/opt/solr -Djetty.port=8085 -Djetty.home=/opt/jetty -Djava.io.tmpdir=/tmp -jar /opt/jetty/start.jar --pre=etc/jetty-logging.xml --daemon

Doing it this way is one way to check and see if a process is there - that's not a usual process - pgrep works great with things like ssh:

root@solr-berkshelf:~# pgrep sshd
1211
11206
11226

But it doesn't find my jetty process - because it's run under java. It does find java:

vagrant@solr-berkshelf:~$ pgrep java
12169

I suppose we could use grep with [j]etty - that would work too.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems grep is better than pgrep, as @darron said.

end

def check_file_contain file, expected_pattern
Expand Down
2 changes: 1 addition & 1 deletion lib/serverspec/version.rb
@@ -1,3 +1,3 @@
module Serverspec
VERSION = "0.1.5"
VERSION = "0.1.6"
end