Class: DogCatcher
- Inherits:
-
Object
- Object
- DogCatcher
- Defined in:
- lib/dog_catcher.rb
Constant Summary collapse
- VERSION =
"0.1"
Instance Attribute Summary collapse
-
#lines ⇒ Object
Returns the value of attribute lines.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ DogCatcher
constructor
A new instance of DogCatcher.
- #running_mongrels ⇒ Object
- #running_rubies ⇒ Object
- #stop_all_mongrels! ⇒ Object
Constructor Details
#initialize ⇒ DogCatcher
Returns a new instance of DogCatcher.
6 7 8 9 |
# File 'lib/dog_catcher.rb', line 6 def initialize @psx = `ps x` @lines = @psx.split(/\n/).collect{|l| DogCatcher.parse_line(l) } end |
Instance Attribute Details
#lines ⇒ Object
Returns the value of attribute lines.
4 5 6 |
# File 'lib/dog_catcher.rb', line 4 def lines @lines end |
Class Method Details
.guess_port(m) ⇒ Object
32 33 34 35 |
# File 'lib/dog_catcher.rb', line 32 def self.guess_port( m ) port_arg = m[:args].scan(/(-p\s\d*)/).first port_arg ? port_arg.first.split(" ").last : "3000" end |
.parse_line(string) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/dog_catcher.rb', line 11 def self.parse_line( string ) arr = string.split(' ') { :pid => arr[0].to_i, :prog => arr[4], :args => arr[5..arr.length-1].join(" ") } end |
.stop_mongrel!(m) ⇒ Object
19 20 21 22 |
# File 'lib/dog_catcher.rb', line 19 def self.stop_mongrel!( m ) puts "Sending 'TERM' to mongrel running on #{m[:pid]}" Process.kill("TERM", m[:pid]) end |
Instance Method Details
#running_mongrels ⇒ Object
28 29 30 |
# File 'lib/dog_catcher.rb', line 28 def running_mongrels self.lines.select{|l| l[:args] =~ /mong/} end |
#running_rubies ⇒ Object
24 25 26 |
# File 'lib/dog_catcher.rb', line 24 def running_rubies self.lines.select{|l| l[:prog] == "ruby" } end |
#stop_all_mongrels! ⇒ Object
37 38 39 |
# File 'lib/dog_catcher.rb', line 37 def stop_all_mongrels! self.running_mongrels.each{|m| DogCatcher.stop_mongrel! m } end |