rails_pwnerer 0.5.2 → 0.5.3
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/CHANGELOG +2 -0
- data/lib/pwnage/app/cluster_config.rb +44 -9
- data/lib/pwnage/app/main.rb +0 -1
- data/lib/pwnage/config/app.rb +9 -1
- data/lib/pwnage/scaffolds/gems.rb +3 -0
- data/lib/rails_pwnage.rb +1 -0
- data/rails_pwnerer.gemspec +2 -2
- metadata +1 -1
data/CHANGELOG
CHANGED
@@ -57,6 +57,38 @@ class RailsPwnage::App::ClusterConfig
|
|
57
57
|
File.delete launch_config if File.exists? launch_config
|
58
58
|
end
|
59
59
|
|
60
|
+
def kill_stray_mongrels(app_name, instance_name)
|
61
|
+
app_config = RailsPwnage::Config[app_name, instance_name]
|
62
|
+
# silently die if the app was completely busted
|
63
|
+
return unless app_config and File.exists? app_config[:app_path]
|
64
|
+
|
65
|
+
# a list of patterns that show up in mongrels' cmdline
|
66
|
+
patterns = ['mongrel', app_config[:app_path] + ' ', 'tmp/pids/mongrel', 'log/mongrel']
|
67
|
+
|
68
|
+
Dir.chdir app_config[:app_path] do
|
69
|
+
# Phase 1: look through PID files and issue kill orders
|
70
|
+
pinfo = process_info()
|
71
|
+
Dir.glob('tmp/pids/*.pid').each do |fname|
|
72
|
+
begin
|
73
|
+
pid = File.open(fname, 'r') { |f| f.read.strip! }
|
74
|
+
# avoid killing innocent victims
|
75
|
+
if pinfo[pid].nil? or patterns.all? { |pattern| pinfo[pid][:cmdline].index pattern }
|
76
|
+
Process.kill 'TERM', pid.to_i
|
77
|
+
end
|
78
|
+
rescue
|
79
|
+
# just in case the file gets wiped before we see it
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
# Phase 2: look through the process table and kill anything that looks good
|
84
|
+
pinfo = process_info()
|
85
|
+
pinfo.each do |pid, info|
|
86
|
+
next unless patterns.all? { |pattern| info[:cmdline].index pattern }
|
87
|
+
Process.kill 'TERM', pid.to_i
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
60
92
|
def stop_mongrels(app_name, instance_name)
|
61
93
|
app_config = RailsPwnage::Config[app_name, instance_name]
|
62
94
|
# silently die if the app was completely busted
|
@@ -64,16 +96,17 @@ class RailsPwnage::App::ClusterConfig
|
|
64
96
|
|
65
97
|
Dir.chdir app_config[:app_path] do
|
66
98
|
system 'mongrel_rails cluster::stop'
|
67
|
-
|
68
|
-
# clean up PID files in case the mongrels died and left them behind
|
69
|
-
Dir.glob('tmp/pids/*.pid').each { |f| File.delete(f) }
|
70
99
|
end
|
100
|
+
sleep 0.5
|
101
|
+
kill_stray_mongrels app_name, instance_name
|
71
102
|
end
|
72
103
|
|
73
104
|
def start_mongrels(app_name, instance_name)
|
74
105
|
app_config = RailsPwnage::Config[app_name, instance_name]
|
75
106
|
# silently die if the app was completely busted
|
76
107
|
return unless app_config and File.exists? app_config[:app_path]
|
108
|
+
|
109
|
+
kill_stray_mongrels app_name, instance_name
|
77
110
|
|
78
111
|
# alloc a port if somehow that slipped through the cracks
|
79
112
|
if app_config[:port0] == 0
|
@@ -119,11 +152,13 @@ class RailsPwnage::App::ClusterConfig
|
|
119
152
|
end
|
120
153
|
|
121
154
|
def control_all(action)
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
155
|
+
RailsPwnage::Config.all_applications.each do |ai|
|
156
|
+
case action
|
157
|
+
when :start
|
158
|
+
RailsPwnage::App::ClusterConfig.new.start_mongrels ai[0], ai[1]
|
159
|
+
when :stop
|
160
|
+
RailsPwnage::App::ClusterConfig.new.stop_mongrels ai[0], ai[1]
|
161
|
+
end
|
162
|
+
end
|
128
163
|
end
|
129
164
|
end
|
data/lib/pwnage/app/main.rb
CHANGED
data/lib/pwnage/config/app.rb
CHANGED
@@ -8,6 +8,14 @@ module RailsPwnage::Config
|
|
8
8
|
|
9
9
|
# the instances of an application installed on this box
|
10
10
|
def self.app_instances(app_name)
|
11
|
-
self.databases().
|
11
|
+
self.databases().select { |db| db.include? ?. }.map { |db| db[0...(db.rindex ?.)] }
|
12
|
+
end
|
13
|
+
|
14
|
+
# all instances of all applications installed on this box
|
15
|
+
def self.all_applications()
|
16
|
+
self.databases().select { |db| db.include? ?. }.map do |db|
|
17
|
+
lastdot = db.rindex ?.
|
18
|
+
[db[0...lastdot], db[(lastdot + 1)..-1]]
|
19
|
+
end
|
12
20
|
end
|
13
21
|
end
|
data/lib/rails_pwnage.rb
CHANGED
data/rails_pwnerer.gemspec
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
|
2
|
-
# Gem::Specification for Rails_pwnerer-0.5.
|
2
|
+
# Gem::Specification for Rails_pwnerer-0.5.3
|
3
3
|
# Originally generated by Echoe
|
4
4
|
|
5
5
|
--- !ruby/object:Gem::Specification
|
6
6
|
name: rails_pwnerer
|
7
7
|
version: !ruby/object:Gem::Version
|
8
|
-
version: 0.5.
|
8
|
+
version: 0.5.3
|
9
9
|
platform: ruby
|
10
10
|
authors:
|
11
11
|
- Victor Costan
|