Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Solaris ps system call command line args fix.

  • Loading branch information...
commit 276ebe2996c73e78c57c9a531271e8e1f5203d4c 1 parent 9b96330
Marc Jakobs authored steveklabnik committed
Showing with 18 additions and 14 deletions.
  1. +18 −14 lib/resque/worker.rb
View
32 lib/resque/worker.rb
@@ -536,28 +536,32 @@ def worker_pids
# Find Resque worker pids on Linux and OS X.
#
- # Returns an Array of string pids of all the other workers on this
- # machine. Useful when pruning dead workers on startup.
def linux_worker_pids
- `ps -A -o pid,command | grep "[r]esque" | grep -v "resque-web"`.split("\n").map do |line|
- line.split(' ')[0]
- end
+ get_worker_pids('ps -A -o pid,command')
end
# Find Resque worker pids on Solaris.
#
- # Returns an Array of string pids of all the other workers on this
- # machine. Useful when pruning dead workers on startup.
def solaris_worker_pids
- `ps -A -o pid,comm | grep "[r]uby" | grep -v "resque-web"`.split("\n").map do |line|
- real_pid = line.split(' ')[0]
- pargs_command = `pargs -a #{real_pid} 2>/dev/null | grep [r]esque | grep -v "resque-web"`
- if pargs_command.split(':')[1] == " resque-#{Resque::Version}"
- real_pid
- end
- end.compact
+ get_worker_pids('ps -A -o pid,args')
end
+ # Find worker pids - platform independent
+ #
+ # Returns an Array of string pids of all the other workers on this
+ # machine. Useful when pruning dead workers on startup.
+ def get_worker_pids(command)
+ active_worker_pids = []
+ output = %x[#{command}] # output format of ps must be ^<PID> <COMMAND WITH ARGS>
+ raise 'System call for ps command failed. Please make sure that you have a compatible ps command in the path!' unless $?.success?
+ output.split("\n").each{|line|
+ next unless line =~ /resque/i
+ next if line =~ /resque-web/
+ active_worker_pids.push line.split(' ')[0]
+ }
+ active_worker_pids
+ end
+
# Given a string, sets the procline ($0) and logs.
# Procline is always in the format of:
# resque-VERSION: STRING
Please sign in to comment.
Something went wrong with that request. Please try again.