Skip to content

Commit 7dea194

Browse files
hirschnasesteveklabnik
authored andcommitted
Solaris ps system call command line args fix.
1 parent 0fc4da9 commit 7dea194

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

lib/resque/worker.rb

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -536,28 +536,32 @@ def worker_pids
536536

537537
# Find Resque worker pids on Linux and OS X.
538538
#
539-
# Returns an Array of string pids of all the other workers on this
540-
# machine. Useful when pruning dead workers on startup.
541539
def linux_worker_pids
542-
`ps -A -o pid,command | grep "[r]esque" | grep -v "resque-web"`.split("\n").map do |line|
543-
line.split(' ')[0]
544-
end
540+
get_worker_pids('ps -A -o pid,command')
545541
end
546542

547543
# Find Resque worker pids on Solaris.
548544
#
549-
# Returns an Array of string pids of all the other workers on this
550-
# machine. Useful when pruning dead workers on startup.
551545
def solaris_worker_pids
552-
`ps -A -o pid,comm | grep "[r]uby" | grep -v "resque-web"`.split("\n").map do |line|
553-
real_pid = line.split(' ')[0]
554-
pargs_command = `pargs -a #{real_pid} 2>/dev/null | grep [r]esque | grep -v "resque-web"`
555-
if pargs_command.split(':')[1] == " resque-#{Resque::Version}"
556-
real_pid
557-
end
558-
end.compact
546+
get_worker_pids('ps -A -o pid,args')
559547
end
560548

549+
# Find worker pids - platform independent
550+
#
551+
# Returns an Array of string pids of all the other workers on this
552+
# machine. Useful when pruning dead workers on startup.
553+
def get_worker_pids(command)
554+
active_worker_pids = []
555+
output = %x[#{command}] # output format of ps must be ^<PID> <COMMAND WITH ARGS>
556+
raise 'System call for ps command failed. Please make sure that you have a compatible ps command in the path!' unless $?.success?
557+
output.split("\n").each{|line|
558+
next unless line =~ /resque/i
559+
next if line =~ /resque-web/
560+
active_worker_pids.push line.split(' ')[0]
561+
}
562+
active_worker_pids
563+
end
564+
561565
# Given a string, sets the procline ($0) and logs.
562566
# Procline is always in the format of:
563567
# resque-VERSION: STRING

0 commit comments

Comments
 (0)