@@ -536,28 +536,32 @@ def worker_pids
536
536
537
537
# Find Resque worker pids on Linux and OS X.
538
538
#
539
- # Returns an Array of string pids of all the other workers on this
540
- # machine. Useful when pruning dead workers on startup.
541
539
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' )
545
541
end
546
542
547
543
# Find Resque worker pids on Solaris.
548
544
#
549
- # Returns an Array of string pids of all the other workers on this
550
- # machine. Useful when pruning dead workers on startup.
551
545
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' )
559
547
end
560
548
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
+
561
565
# Given a string, sets the procline ($0) and logs.
562
566
# Procline is always in the format of:
563
567
# resque-VERSION: STRING
0 commit comments