thin 0.6.2 → 0.6.3

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of thin might be problematic. Click here for more details.

Files changed (49) hide show
  1. data/CHANGELOG +34 -0
  2. data/bin/thin +2 -164
  3. data/example/config.ru +4 -1
  4. data/example/ramaze.ru +12 -0
  5. data/example/thin.god +70 -66
  6. data/example/vlad.rake +61 -0
  7. data/lib/rack/adapter/rails.rb +0 -3
  8. data/lib/rack/handler/thin.rb +6 -1
  9. data/lib/thin.rb +13 -4
  10. data/lib/thin/command.rb +9 -5
  11. data/lib/thin/connection.rb +5 -14
  12. data/lib/thin/connectors/connector.rb +61 -0
  13. data/lib/thin/connectors/tcp_server.rb +29 -0
  14. data/lib/thin/connectors/unix_server.rb +48 -0
  15. data/lib/thin/controllers/cluster.rb +115 -0
  16. data/lib/thin/controllers/controller.rb +85 -0
  17. data/lib/thin/controllers/service.rb +73 -0
  18. data/lib/thin/controllers/service.sh.erb +39 -0
  19. data/lib/thin/daemonizing.rb +9 -4
  20. data/lib/thin/headers.rb +2 -2
  21. data/lib/thin/runner.rb +166 -0
  22. data/lib/thin/server.rb +109 -89
  23. data/lib/thin/stats.html.erb +216 -0
  24. data/lib/thin/stats.rb +1 -249
  25. data/lib/thin/version.rb +10 -3
  26. data/spec/command_spec.rb +0 -1
  27. data/spec/configs/cluster.yml +9 -0
  28. data/spec/configs/single.yml +9 -0
  29. data/spec/{cluster_spec.rb → controllers/cluster_spec.rb} +22 -10
  30. data/spec/controllers/controller_spec.rb +85 -0
  31. data/spec/controllers/service_spec.rb +51 -0
  32. data/spec/daemonizing_spec.rb +73 -9
  33. data/spec/request/mongrel_spec.rb +39 -0
  34. data/spec/{request_spec.rb → request/parser_spec.rb} +11 -143
  35. data/spec/request/perf_spec.rb +50 -0
  36. data/spec/request/processing_spec.rb +46 -0
  37. data/spec/runner_spec.rb +135 -0
  38. data/spec/server/builder_spec.rb +38 -0
  39. data/spec/server/stopping_spec.rb +45 -0
  40. data/spec/server/tcp_spec.rb +54 -0
  41. data/spec/server/unix_socket_spec.rb +30 -0
  42. data/spec/spec_helper.rb +49 -16
  43. data/tasks/announce.rake +7 -3
  44. data/tasks/email.erb +8 -18
  45. data/tasks/gem.rake +8 -1
  46. data/tasks/stats.rake +21 -8
  47. metadata +33 -6
  48. data/lib/thin/cluster.rb +0 -123
  49. data/spec/server_spec.rb +0 -200
@@ -0,0 +1,216 @@
1
+ <%#
2
+ # Taken from Rack::ShowException
3
+ # adapted from Django <djangoproject.com>
4
+ # Copyright (c) 2005, the Lawrence Journal-World
5
+ # Used under the modified BSD license:
6
+ # http://www.xfree86.org/3.3.6/COPYRIGHT2.html#5
7
+ %>
8
+ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
9
+ <html lang="en">
10
+ <head>
11
+ <meta http-equiv="content-type" content="text/html; charset=utf-8" />
12
+ <meta name="robots" content="NONE,NOARCHIVE" />
13
+ <title>Thin Stats</title>
14
+ <style type="text/css">
15
+ html * { padding:0; margin:0; }
16
+ body * { padding:10px 20px; }
17
+ body * * { padding:0; }
18
+ body { font:small sans-serif; }
19
+ body>div { border-bottom:1px solid #ddd; }
20
+ h1 { font-weight:normal; }
21
+ h2 { margin-bottom:.8em; }
22
+ h2 span { font-size:80%; color:#666; font-weight:normal; }
23
+ h3 { margin:1em 0 .5em 0; }
24
+ h4 { margin:0 0 .5em 0; font-weight: normal; }
25
+ table {
26
+ border:1px solid #ccc; border-collapse: collapse; background:white; }
27
+ tbody td, tbody th { vertical-align:top; padding:2px 3px; }
28
+ thead th {
29
+ padding:1px 6px 1px 3px; background:#fefefe; text-align:left;
30
+ font-weight:normal; font-size:11px; border:1px solid #ddd; }
31
+ tbody th { text-align:right; color:#666; padding-right:.5em; }
32
+ table.vars { margin:5px 0 2px 40px; }
33
+ table.vars td, table.req td { font-family:monospace; }
34
+ table td.code { width:100%;}
35
+ table td.code div { overflow:hidden; }
36
+ table.source th { color:#666; }
37
+ table.source td {
38
+ font-family:monospace; white-space:pre; border-bottom:1px solid #eee; }
39
+ ul.traceback { list-style-type:none; }
40
+ ul.traceback li.frame { margin-bottom:1em; }
41
+ div.context { margin: 10px 0; }
42
+ div.context ol {
43
+ padding-left:30px; margin:0 10px; list-style-position: inside; }
44
+ div.context ol li {
45
+ font-family:monospace; white-space:pre; color:#666; cursor:pointer; }
46
+ div.context ol.context-line li { color:black; background-color:#ccc; }
47
+ div.context ol.context-line li span { float: right; }
48
+ div.commands { margin-left: 40px; }
49
+ div.commands a { color:black; text-decoration:none; }
50
+ #summary { background: #ffc; }
51
+ #summary h2 { font-weight: normal; color: #666; }
52
+ #summary ul#quicklinks { list-style-type: none; margin-bottom: 2em; }
53
+ #summary ul#quicklinks li { float: left; padding: 0 1em; }
54
+ #summary ul#quicklinks>li+li { border-left: 1px #666 solid; }
55
+ #explanation { background:#eee; }
56
+ #template, #template-not-exist { background:#f6f6f6; }
57
+ #template-not-exist ul { margin: 0 0 0 20px; }
58
+ #traceback { background:#eee; }
59
+ #summary table { border:none; background:transparent; }
60
+ #requests { background:#f6f6f6; padding-left:120px; }
61
+ #requests h2, #requests h3 { position:relative; margin-left:-100px; }
62
+ #requests h3 { margin-bottom:-1em; }
63
+ .error { background: #ffc; }
64
+ .specific { color:#cc3300; font-weight:bold; }
65
+ </style>
66
+ </head>
67
+ <body>
68
+
69
+ <div id="summary">
70
+ <h1>Server stats</h1>
71
+ <h2><%= Thin::SERVER %></h2>
72
+ <table>
73
+ <tr>
74
+ <th>Uptime</th>
75
+ <td><%= Time.now - @start_time %> sec</td>
76
+ </tr>
77
+ <tr>
78
+ <th>PID</th>
79
+ <td><%=h Process.pid %></td>
80
+ </tr>
81
+ </table>
82
+
83
+ <% if @last_request %>
84
+ <h3>Jump to:</h3>
85
+ <ul id="quicklinks">
86
+ <li><a href="#get-info">GET</a></li>
87
+ <li><a href="#post-info">POST</a></li>
88
+ <li><a href="#cookie-info">Cookies</a></li>
89
+ <li><a href="#env-info">ENV</a></li>
90
+ </ul>
91
+ <% end %>
92
+ </div>
93
+
94
+ <div id="stats">
95
+ <h2>Requests</h2>
96
+ <h3>Stats</h3>
97
+ <table class="req">
98
+ <tr>
99
+ <td>Requests</td>
100
+ <td><%= @requests %></td>
101
+ </tr>
102
+ <tr>
103
+ <td>Finished</td>
104
+ <td><%= @requests_finished %></td>
105
+ </tr>
106
+ <tr>
107
+ <td>Errors</td>
108
+ <td><%= @requests - @requests_finished %></td>
109
+ </tr>
110
+ <tr>
111
+ <td>Last request</td>
112
+ <td><%= @last_request_time %> sec</td>
113
+ </tr>
114
+ </table>
115
+ </div>
116
+
117
+ <% if @last_request %>
118
+ <div id="requestinfo">
119
+ <h2>Last Request information</h2>
120
+
121
+ <h3 id="get-info">GET</h3>
122
+ <% unless @last_request.GET.empty? %>
123
+ <table class="req">
124
+ <thead>
125
+ <tr>
126
+ <th>Variable</th>
127
+ <th>Value</th>
128
+ </tr>
129
+ </thead>
130
+ <tbody>
131
+ <% @last_request.GET.sort_by { |k, v| k.to_s }.each { |key, val| %>
132
+ <tr>
133
+ <td><%=h key %></td>
134
+ <td class="code"><div><%=h val.inspect %></div></td>
135
+ </tr>
136
+ <% } %>
137
+ </tbody>
138
+ </table>
139
+ <% else %>
140
+ <p>No GET data.</p>
141
+ <% end %>
142
+
143
+ <h3 id="post-info">POST</h3>
144
+ <% unless @last_request.POST.empty? %>
145
+ <table class="req">
146
+ <thead>
147
+ <tr>
148
+ <th>Variable</th>
149
+ <th>Value</th>
150
+ </tr>
151
+ </thead>
152
+ <tbody>
153
+ <% @last_request.POST.sort_by { |k, v| k.to_s }.each { |key, val| %>
154
+ <tr>
155
+ <td><%=h key %></td>
156
+ <td class="code"><div><%=h val.inspect %></div></td>
157
+ </tr>
158
+ <% } %>
159
+ </tbody>
160
+ </table>
161
+ <% else %>
162
+ <p>No POST data.</p>
163
+ <% end %>
164
+
165
+
166
+ <h3 id="cookie-info">COOKIES</h3>
167
+ <% unless @last_request.cookies.empty? %>
168
+ <table class="req">
169
+ <thead>
170
+ <tr>
171
+ <th>Variable</th>
172
+ <th>Value</th>
173
+ </tr>
174
+ </thead>
175
+ <tbody>
176
+ <% @last_request.cookies.each { |key, val| %>
177
+ <tr>
178
+ <td><%=h key %></td>
179
+ <td class="code"><div><%=h val.inspect %></div></td>
180
+ </tr>
181
+ <% } %>
182
+ </tbody>
183
+ </table>
184
+ <% else %>
185
+ <p>No cookie data.</p>
186
+ <% end %>
187
+
188
+ <h3 id="env-info">Rack ENV</h3>
189
+ <table class="req">
190
+ <thead>
191
+ <tr>
192
+ <th>Variable</th>
193
+ <th>Value</th>
194
+ </tr>
195
+ </thead>
196
+ <tbody>
197
+ <% @last_request.env.sort_by { |k, v| k.to_s }.each { |key, val| %>
198
+ <tr>
199
+ <td><%=h key %></td>
200
+ <td class="code"><div><%=h val %></div></td>
201
+ </tr>
202
+ <% } %>
203
+ </tbody>
204
+ </table>
205
+
206
+ </div>
207
+ <% end %>
208
+
209
+ <div id="explanation">
210
+ <p>
211
+ You're seeing this page because you use <code>Thin::Stats</code>.
212
+ </p>
213
+ </div>
214
+
215
+ </body>
216
+ </html>
data/lib/thin/stats.rb CHANGED
@@ -10,7 +10,7 @@ module Thin
10
10
  @app = app
11
11
  @path = path
12
12
 
13
- @template = ERB.new(TEMPLATE)
13
+ @template = ERB.new(File.read(File.dirname(__FILE__) + '/stats.html.erb'))
14
14
 
15
15
  @requests = 0
16
16
  @requests_finished = 0
@@ -50,254 +50,6 @@ module Thin
50
50
  [body]
51
51
  ]
52
52
  end
53
-
54
- # Taken from Rails
55
- def distance_of_time_in_words(from_time, to_time = 0, include_seconds = false)
56
- from_time = from_time.to_time if from_time.respond_to?(:to_time)
57
- to_time = to_time.to_time if to_time.respond_to?(:to_time)
58
- distance_in_minutes = (((to_time - from_time).abs)/60).round
59
- distance_in_seconds = ((to_time - from_time).abs).round
60
-
61
- case distance_in_minutes
62
- when 0..1
63
- return (distance_in_minutes == 0) ? 'less than a minute' : '1 minute' unless include_seconds
64
- case distance_in_seconds
65
- when 0..4 then 'less than 5 seconds'
66
- when 5..9 then 'less than 10 seconds'
67
- when 10..19 then 'less than 20 seconds'
68
- when 20..39 then 'half a minute'
69
- when 40..59 then 'less than a minute'
70
- else '1 minute'
71
- end
72
-
73
- when 2..44 then "#{distance_in_minutes} minutes"
74
- when 45..89 then 'about 1 hour'
75
- when 90..1439 then "about #{(distance_in_minutes.to_f / 60.0).round} hours"
76
- when 1440..2879 then '1 day'
77
- when 2880..43199 then "#{(distance_in_minutes / 1440).round} days"
78
- when 43200..86399 then 'about 1 month'
79
- when 86400..525599 then "#{(distance_in_minutes / 43200).round} months"
80
- when 525600..1051199 then 'about 1 year'
81
- else "over #{(distance_in_minutes / 525600).round} years"
82
- end
83
- end
84
-
85
- # Taken from Rack::ShowException
86
- # adapted from Django <djangoproject.com>
87
- # Copyright (c) 2005, the Lawrence Journal-World
88
- # Used under the modified BSD license:
89
- # http://www.xfree86.org/3.3.6/COPYRIGHT2.html#5
90
- TEMPLATE = <<'HTML'
91
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
92
- <html lang="en">
93
- <head>
94
- <meta http-equiv="content-type" content="text/html; charset=utf-8" />
95
- <meta name="robots" content="NONE,NOARCHIVE" />
96
- <title>Thin Stats</title>
97
- <style type="text/css">
98
- html * { padding:0; margin:0; }
99
- body * { padding:10px 20px; }
100
- body * * { padding:0; }
101
- body { font:small sans-serif; }
102
- body>div { border-bottom:1px solid #ddd; }
103
- h1 { font-weight:normal; }
104
- h2 { margin-bottom:.8em; }
105
- h2 span { font-size:80%; color:#666; font-weight:normal; }
106
- h3 { margin:1em 0 .5em 0; }
107
- h4 { margin:0 0 .5em 0; font-weight: normal; }
108
- table {
109
- border:1px solid #ccc; border-collapse: collapse; background:white; }
110
- tbody td, tbody th { vertical-align:top; padding:2px 3px; }
111
- thead th {
112
- padding:1px 6px 1px 3px; background:#fefefe; text-align:left;
113
- font-weight:normal; font-size:11px; border:1px solid #ddd; }
114
- tbody th { text-align:right; color:#666; padding-right:.5em; }
115
- table.vars { margin:5px 0 2px 40px; }
116
- table.vars td, table.req td { font-family:monospace; }
117
- table td.code { width:100%;}
118
- table td.code div { overflow:hidden; }
119
- table.source th { color:#666; }
120
- table.source td {
121
- font-family:monospace; white-space:pre; border-bottom:1px solid #eee; }
122
- ul.traceback { list-style-type:none; }
123
- ul.traceback li.frame { margin-bottom:1em; }
124
- div.context { margin: 10px 0; }
125
- div.context ol {
126
- padding-left:30px; margin:0 10px; list-style-position: inside; }
127
- div.context ol li {
128
- font-family:monospace; white-space:pre; color:#666; cursor:pointer; }
129
- div.context ol.context-line li { color:black; background-color:#ccc; }
130
- div.context ol.context-line li span { float: right; }
131
- div.commands { margin-left: 40px; }
132
- div.commands a { color:black; text-decoration:none; }
133
- #summary { background: #ffc; }
134
- #summary h2 { font-weight: normal; color: #666; }
135
- #summary ul#quicklinks { list-style-type: none; margin-bottom: 2em; }
136
- #summary ul#quicklinks li { float: left; padding: 0 1em; }
137
- #summary ul#quicklinks>li+li { border-left: 1px #666 solid; }
138
- #explanation { background:#eee; }
139
- #template, #template-not-exist { background:#f6f6f6; }
140
- #template-not-exist ul { margin: 0 0 0 20px; }
141
- #traceback { background:#eee; }
142
- #summary table { border:none; background:transparent; }
143
- #requests { background:#f6f6f6; padding-left:120px; }
144
- #requests h2, #requests h3 { position:relative; margin-left:-100px; }
145
- #requests h3 { margin-bottom:-1em; }
146
- .error { background: #ffc; }
147
- .specific { color:#cc3300; font-weight:bold; }
148
- </style>
149
- </head>
150
- <body>
151
-
152
- <div id="summary">
153
- <h1>Server stats</h1>
154
- <h2><%= Thin::SERVER %></h2>
155
- <table>
156
- <tr>
157
- <th>Uptime</th>
158
- <td><%= distance_of_time_in_words(@start_time, Time.now) %> (<%= Time.now - @start_time %> sec)</td>
159
- </tr>
160
- <tr>
161
- <th>PID</th>
162
- <td><%=h Process.pid %></td>
163
- </tr>
164
- </table>
165
-
166
- <% if @last_request %>
167
- <h3>Jump to:</h3>
168
- <ul id="quicklinks">
169
- <li><a href="#get-info">GET</a></li>
170
- <li><a href="#post-info">POST</a></li>
171
- <li><a href="#cookie-info">Cookies</a></li>
172
- <li><a href="#env-info">ENV</a></li>
173
- </ul>
174
- <% end %>
175
- </div>
176
-
177
- <div id="stats">
178
- <h2>Requests</h2>
179
- <h3>Stats</h3>
180
- <table class="req">
181
- <tr>
182
- <td>Requests</td>
183
- <td><%= @requests %></td>
184
- </tr>
185
- <tr>
186
- <td>Finished</td>
187
- <td><%= @requests_finished %></td>
188
- </tr>
189
- <tr>
190
- <td>Errors</td>
191
- <td><%= @requests - @requests_finished %></td>
192
- </tr>
193
- <tr>
194
- <td>Last request</td>
195
- <td><%= @last_request_time %> sec</td>
196
- </tr>
197
- </table>
198
- </div>
199
-
200
- <% if @last_request %>
201
- <div id="requestinfo">
202
- <h2>Last Request information</h2>
203
-
204
- <h3 id="get-info">GET</h3>
205
- <% unless @last_request.GET.empty? %>
206
- <table class="req">
207
- <thead>
208
- <tr>
209
- <th>Variable</th>
210
- <th>Value</th>
211
- </tr>
212
- </thead>
213
- <tbody>
214
- <% @last_request.GET.sort_by { |k, v| k.to_s }.each { |key, val| %>
215
- <tr>
216
- <td><%=h key %></td>
217
- <td class="code"><div><%=h val.inspect %></div></td>
218
- </tr>
219
- <% } %>
220
- </tbody>
221
- </table>
222
- <% else %>
223
- <p>No GET data.</p>
224
- <% end %>
225
-
226
- <h3 id="post-info">POST</h3>
227
- <% unless @last_request.POST.empty? %>
228
- <table class="req">
229
- <thead>
230
- <tr>
231
- <th>Variable</th>
232
- <th>Value</th>
233
- </tr>
234
- </thead>
235
- <tbody>
236
- <% @last_request.POST.sort_by { |k, v| k.to_s }.each { |key, val| %>
237
- <tr>
238
- <td><%=h key %></td>
239
- <td class="code"><div><%=h val.inspect %></div></td>
240
- </tr>
241
- <% } %>
242
- </tbody>
243
- </table>
244
- <% else %>
245
- <p>No POST data.</p>
246
- <% end %>
247
-
248
-
249
- <h3 id="cookie-info">COOKIES</h3>
250
- <% unless @last_request.cookies.empty? %>
251
- <table class="req">
252
- <thead>
253
- <tr>
254
- <th>Variable</th>
255
- <th>Value</th>
256
- </tr>
257
- </thead>
258
- <tbody>
259
- <% @last_request.cookies.each { |key, val| %>
260
- <tr>
261
- <td><%=h key %></td>
262
- <td class="code"><div><%=h val.inspect %></div></td>
263
- </tr>
264
- <% } %>
265
- </tbody>
266
- </table>
267
- <% else %>
268
- <p>No cookie data.</p>
269
- <% end %>
270
-
271
- <h3 id="env-info">Rack ENV</h3>
272
- <table class="req">
273
- <thead>
274
- <tr>
275
- <th>Variable</th>
276
- <th>Value</th>
277
- </tr>
278
- </thead>
279
- <tbody>
280
- <% @last_request.env.sort_by { |k, v| k.to_s }.each { |key, val| %>
281
- <tr>
282
- <td><%=h key %></td>
283
- <td class="code"><div><%=h val %></div></td>
284
- </tr>
285
- <% } %>
286
- </tbody>
287
- </table>
288
-
289
- </div>
290
- <% end %>
291
-
292
- <div id="explanation">
293
- <p>
294
- You're seeing this error because you use <code>Thin::Stats</code>.
295
- </p>
296
- </div>
297
-
298
- </body>
299
- </html>
300
- HTML
301
53
  end
302
54
  end
303
55
  end