zombie_passenger_killer 0.2.4 → 0.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- zombie_passenger_killer (0.2.4)
4
+ zombie_passenger_killer (0.2.5)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
@@ -27,22 +27,6 @@ module ZombiePassengerKiller
27
27
  raise $!
28
28
  end
29
29
 
30
- def store_current_cpu(processes)
31
- keys_to_remove = @history.keys - processes.map{|x| x[:pid] }
32
- keys_to_remove.each{|k| !@history.delete k }
33
-
34
- processes.each do |process|
35
- @history[process[:pid]] ||= []
36
- @history[process[:pid]] << process[:cpu]
37
- @history[process[:pid]] = @history[process[:pid]].last(@history_entries)
38
- end
39
- end
40
-
41
- def get_strace(pid, time)
42
- Process.getpgid(pid) rescue return 'No such process'
43
- `( strace -p #{pid} 2>&1 ) & sleep #{time} ; kill $! 2>&1`
44
- end
45
-
46
30
  def hunt_zombies
47
31
  active_pids_in_passenger_status = passenger_pids
48
32
  active_processes_in_processlist = process_status
@@ -63,6 +47,24 @@ module ZombiePassengerKiller
63
47
  end
64
48
  end
65
49
 
50
+ private
51
+
52
+ def store_current_cpu(processes)
53
+ keys_to_remove = @history.keys - processes.map{|x| x[:pid] }
54
+ keys_to_remove.each{|k| !@history.delete k }
55
+
56
+ processes.each do |process|
57
+ @history[process[:pid]] ||= []
58
+ @history[process[:pid]] << process[:cpu]
59
+ @history[process[:pid]] = @history[process[:pid]].last(@history_entries)
60
+ end
61
+ end
62
+
63
+ def get_strace(pid, time)
64
+ Process.getpgid(pid) rescue return 'No such process'
65
+ `( strace -p #{pid} 2>&1 ) & sleep #{time} ; kill $! 2>&1`
66
+ end
67
+
66
68
  # return array of pids reported from passenger-status command, nil if passenger-status doesn't run
67
69
  def passenger_pids
68
70
  pids = %x(#{'rvmsudo ' if @rvmsudo}passenger-status|grep PID).split("\n").map { |x| x.strip.match(/PID: \d*/).to_s.split[1].to_i }
@@ -70,7 +72,7 @@ module ZombiePassengerKiller
70
72
  end
71
73
 
72
74
  def process_status
73
- %x(ps -eo pid,pcpu,args|grep -v grep|grep '#{@pattern}').split("\n").map do |line|
75
+ %x(ps -eo pid,pcpu,args|grep -v grep|egrep '#{@pattern}').split("\n").map do |line|
74
76
  values = line.strip.split[0..1]
75
77
  {:pid => values.first.to_i, :cpu => values.last.to_f}
76
78
  end
@@ -1,3 +1,3 @@
1
1
  module ZombiePassengerKiller
2
- Version = VERSION = '0.2.4'
2
+ Version = VERSION = '0.2.5'
3
3
  end
@@ -103,7 +103,7 @@ describe ZombiePassengerKiller do
103
103
  it "kills normal processes" do
104
104
  pid = start_bogus_process
105
105
  lambda{
106
- killer.kill_zombie(pid)
106
+ killer.send(:kill_zombie, pid)
107
107
  sleep 0.1
108
108
  }.should change{ process_alive?(pid) }
109
109
  end
@@ -111,37 +111,37 @@ describe ZombiePassengerKiller do
111
111
  it "kills hanging processes" do
112
112
  pid = start_bogus_process :hang => true
113
113
  lambda{
114
- killer.kill_zombie(pid)
114
+ killer.send(:kill_zombie, pid)
115
115
  sleep 0.1
116
116
  }.should change{ process_alive?(pid) }
117
117
  end
118
118
 
119
119
  it "prints an strace of the process" do
120
120
  pid = start_bogus_process
121
- killer.kill_zombie(pid)
121
+ killer.send(:kill_zombie, pid)
122
122
  output.should include('attach:')
123
123
  end
124
124
 
125
125
  it "does not take a strace of a dead process" do
126
- killer.kill_zombie(111)
126
+ killer.send(:kill_zombie, 111)
127
127
  output.should_not include('attach:')
128
128
  end
129
129
 
130
130
  it "does not fail with an unknown pid" do
131
- killer.kill_zombie(111)
131
+ killer.send(:kill_zombie, 111)
132
132
  output.should include('No such process')
133
133
  end
134
134
  end
135
135
 
136
136
  describe "#log" do
137
137
  it "logs simple when :show_times is not given" do
138
- killer.log "X"
138
+ killer.send(:log, "X")
139
139
  output.should == "X\n"
140
140
  end
141
141
 
142
142
  it "logs simple when :show_times is not given" do
143
143
  @options = {:show_times => true}
144
- killer.log "X"
144
+ killer.send(:log, "X")
145
145
  output.should include(Time.now.year.to_s)
146
146
  end
147
147
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zombie_passenger_killer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -45,7 +45,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
45
45
  version: '0'
46
46
  segments:
47
47
  - 0
48
- hash: -4207878518223099064
48
+ hash: -3534877582481648676
49
49
  required_rubygems_version: !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
@@ -54,7 +54,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
54
54
  version: '0'
55
55
  segments:
56
56
  - 0
57
- hash: -4207878518223099064
57
+ hash: -3534877582481648676
58
58
  requirements: []
59
59
  rubyforge_project:
60
60
  rubygems_version: 1.8.24