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

Conversation

@darron
Copy link
Contributor

@darron darron commented Apr 3, 2013

I'm not sure how cross platform it is - but it appears to work on Ubuntu linux.

There's a few other options to do this - lots of info here:

http://serverfault.com/questions/367921/how-to-prevent-ps-reporting-its-own-process

This was the simplest and works properly in my test case.

@@ -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

@raphink raphink Apr 3, 2013

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

@darron darron Apr 3, 2013

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

@raphink raphink Apr 3, 2013

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

@darron darron Apr 4, 2013

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

@mizzy mizzy Apr 4, 2013

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

mizzy added a commit that referenced this issue Apr 4, 2013
This fix hides the grep process from the first grep - which now notifies you if your process is not running.
@mizzy mizzy merged commit e4d1c29 into mizzy:master Apr 4, 2013
1 check failed
@mizzy
Copy link
Owner

@mizzy mizzy commented Apr 4, 2013

Released as v0.1.6. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants