puma 2.16.0-java → 3.0.0-java

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

Potentially problematic release.


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

data/lib/puma.rb CHANGED
@@ -12,3 +12,4 @@ require 'thread'
12
12
  # Ruby Puma
13
13
  require 'puma/const'
14
14
  require 'puma/server'
15
+ require 'puma/launcher'
@@ -49,7 +49,7 @@ module Puma
49
49
  end
50
50
 
51
51
  when /\/reload-worker-directory$/
52
- if !@cli.reload_worker_directory
52
+ if !@cli.send(:reload_worker_directory)
53
53
  return rack_response(404, '{ "error": "reload_worker_directory not available" }')
54
54
  else
55
55
  return rack_response(200, OK_STATUS)
data/lib/puma/binder.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'puma/const'
2
+ require 'uri'
2
3
 
3
4
  module Puma
4
5
  class Binder
@@ -110,6 +111,7 @@ module Puma
110
111
 
111
112
  umask = nil
112
113
  mode = nil
114
+ backlog = nil
113
115
 
114
116
  if uri.query
115
117
  params = Util.parse_query uri.query
@@ -121,9 +123,13 @@ module Puma
121
123
  if u = params['mode']
122
124
  mode = Integer('0'+u)
123
125
  end
126
+
127
+ if u = params['backlog']
128
+ backlog = Integer(u)
129
+ end
124
130
  end
125
131
 
126
- io = add_unix_listener path, umask, mode
132
+ io = add_unix_listener path, umask, mode, backlog
127
133
  end
128
134
 
129
135
  @listeners << [str, io]
@@ -165,7 +171,7 @@ module Puma
165
171
  @events.error "Please specify the SSL ca via 'ca='"
166
172
  end
167
173
  end
168
-
174
+
169
175
  ctx.ca = params['ca'] if params['ca']
170
176
 
171
177
  if params['verify_mode']
@@ -237,10 +243,14 @@ module Puma
237
243
  end
238
244
  s.setsockopt(Socket::SOL_SOCKET,Socket::SO_REUSEADDR, true)
239
245
  s.listen backlog
246
+ @connected_port = s.addr[1]
247
+
240
248
  @ios << s
241
249
  s
242
250
  end
243
251
 
252
+ attr_reader :connected_port
253
+
244
254
  def inherit_tcp_listener(host, port, fd)
245
255
  if fd.kind_of? TCPServer
246
256
  s = fd
@@ -293,7 +303,7 @@ module Puma
293
303
 
294
304
  # Tell the server to listen on +path+ as a UNIX domain socket.
295
305
  #
296
- def add_unix_listener(path, umask=nil, mode=nil)
306
+ def add_unix_listener(path, umask=nil, mode=nil, backlog=nil)
297
307
  @unix_paths << path
298
308
 
299
309
  # Let anyone connect by default
@@ -314,6 +324,7 @@ module Puma
314
324
  end
315
325
 
316
326
  s = UNIXServer.new(path)
327
+ s.listen backlog if backlog
317
328
  @ios << s
318
329
  ensure
319
330
  File.umask old_mask
data/lib/puma/cli.rb CHANGED
@@ -1,17 +1,7 @@
1
1
  require 'optparse'
2
2
  require 'uri'
3
3
 
4
- require 'puma/server'
5
- require 'puma/const'
6
- require 'puma/configuration'
7
- require 'puma/binder'
8
- require 'puma/detect'
9
- require 'puma/daemon_ext'
10
- require 'puma/util'
11
- require 'puma/single'
12
- require 'puma/cluster'
13
-
14
- require 'puma/commonlogger'
4
+ require 'puma/launcher'
15
5
 
16
6
  module Puma
17
7
  class << self
@@ -25,11 +15,7 @@ module Puma
25
15
  # Handles invoke a Puma::Server in a command line style.
26
16
  #
27
17
  class CLI
28
- KEYS_NOT_TO_PERSIST_IN_STATE = [
29
- :logger, :lowlevel_error_handler,
30
- :before_worker_shutdown, :before_worker_boot, :before_worker_fork,
31
- :after_worker_boot, :before_fork, :on_restart
32
- ]
18
+ KEYS_NOT_TO_PERSIST_IN_STATE = Launcher::KEYS_NOT_TO_PERSIST_IN_STATE
33
19
 
34
20
  # Create a new CLI object using +argv+ as the command line
35
21
  # arguments.
@@ -39,544 +25,193 @@ module Puma
39
25
  #
40
26
  def initialize(argv, events=Events.stdio)
41
27
  @debug = false
42
- @argv = argv
28
+ @argv = argv.dup
43
29
 
44
30
  @events = events
45
31
 
46
- @status = nil
47
- @runner = nil
32
+ @conf = nil
48
33
 
49
- @config = nil
34
+ @stdout = nil
35
+ @stderr = nil
36
+ @append = false
50
37
 
51
- setup_options
52
- generate_restart_data
53
-
54
- @binder = Binder.new(@events)
55
- @binder.import_from_env
56
- end
57
-
58
- # The Binder object containing the sockets bound to.
59
- attr_reader :binder
60
-
61
- # The Configuration object used.
62
- attr_reader :config
63
-
64
- # The Hash of options used to configure puma.
65
- attr_reader :options
66
-
67
- # The Events object used to output information.
68
- attr_reader :events
69
-
70
- # Delegate +log+ to +@events+
71
- #
72
- def log(str)
73
- @events.log str
74
- end
75
-
76
- # Delegate +error+ to +@events+
77
- #
78
- def error(str)
79
- @events.error str
80
- end
81
-
82
- def debug(str)
83
- @events.log "- #{str}" if @options[:debug]
84
- end
85
-
86
- def clustered?
87
- @options[:workers] > 0
88
- end
89
-
90
- def prune_bundler?
91
- @options[:prune_bundler] && clustered? && !@options[:preload_app]
92
- end
93
-
94
- def jruby?
95
- IS_JRUBY
96
- end
97
-
98
- def windows?
99
- RUBY_PLATFORM =~ /mswin32|ming32/
100
- end
101
-
102
- def env
103
- @options[:environment] || @cli_options[:environment] || ENV['RACK_ENV'] || 'development'
104
- end
38
+ @control_url = nil
39
+ @control_options = {}
105
40
 
106
- def write_state
107
- write_pid
108
-
109
- path = @options[:state]
110
- return unless path
111
-
112
- state = { 'pid' => Process.pid }
113
- cfg = @config.dup
114
-
115
- KEYS_NOT_TO_PERSIST_IN_STATE.each { |k| cfg.options.delete(k) }
116
- state['config'] = cfg
117
-
118
- require 'yaml'
119
- File.open(path, 'w') { |f| f.write state.to_yaml }
120
- end
121
-
122
- # If configured, write the pid of the current process out
123
- # to a file.
124
- #
125
- def write_pid
126
- path = @options[:pidfile]
127
- return unless path
128
-
129
- File.open(path, 'w') { |f| f.puts Process.pid }
130
- cur = Process.pid
131
- at_exit do
132
- delete_pidfile if cur == Process.pid
133
- end
134
- end
135
-
136
- def delete_pidfile
137
- path = @options[:pidfile]
138
- File.unlink(path) if path && File.exist?(path)
139
- end
140
-
141
- def graceful_stop
142
- @runner.stop_blocked
143
- log "=== puma shutdown: #{Time.now} ==="
144
- log "- Goodbye!"
145
- end
146
-
147
- def jruby_daemon_start
148
- require 'puma/jruby_restart'
149
- JRubyRestart.daemon_start(@restart_dir, restart_args)
150
- end
41
+ setup_options
151
42
 
152
- def restart!
153
- @options[:on_restart].each do |block|
154
- block.call self
155
- end
43
+ begin
44
+ @parser.parse! @argv
156
45
 
157
- if jruby?
158
- close_binder_listeners
159
-
160
- require 'puma/jruby_restart'
161
- JRubyRestart.chdir_exec(@restart_dir, restart_args)
162
- elsif windows?
163
- close_binder_listeners
164
-
165
- argv = restart_args
166
- Dir.chdir(@restart_dir)
167
- argv += [redirects] if RUBY_VERSION >= '1.9'
168
- Kernel.exec(*argv)
169
- else
170
- redirects = {:close_others => true}
171
- @binder.listeners.each_with_index do |(l, io), i|
172
- ENV["PUMA_INHERIT_#{i}"] = "#{io.to_i}:#{l}"
173
- redirects[io.to_i] = io.to_i
46
+ if file = @argv.shift
47
+ @conf.configure do |c|
48
+ c.rackup file
49
+ end
174
50
  end
175
-
176
- argv = restart_args
177
- Dir.chdir(@restart_dir)
178
- argv += [redirects] if RUBY_VERSION >= '1.9'
179
- Kernel.exec(*argv)
180
- end
181
- end
182
-
183
- # Parse the options, load the rackup, start the server and wait
184
- # for it to finish.
185
- #
186
- def run
187
- begin
188
- parse_options
189
51
  rescue UnsupportedOption
190
52
  exit 1
191
53
  end
192
54
 
193
- dir = @options[:directory]
194
- Dir.chdir(dir) if dir
195
-
196
- prune_bundler if prune_bundler?
197
-
198
- set_rack_environment
199
-
200
- if clustered?
201
- @events.formatter = Events::PidFormatter.new
202
- @options[:logger] = @events
203
-
204
- @runner = Cluster.new(self)
205
- else
206
- @runner = Single.new(self)
207
- end
208
-
209
- setup_signals
210
- set_process_title
211
-
212
- @status = :run
213
-
214
- @runner.run
215
-
216
- case @status
217
- when :halt
218
- log "* Stopping immediately!"
219
- when :run, :stop
220
- graceful_stop
221
- when :restart
222
- log "* Restarting..."
223
- @runner.before_restart
224
- restart!
225
- when :exit
226
- # nothing
227
- end
228
- end
229
-
230
- def stop
231
- @status = :stop
232
- @runner.stop
233
- end
234
-
235
- def restart
236
- @status = :restart
237
- @runner.restart
238
- end
239
-
240
- def reload_worker_directory
241
- @runner.reload_worker_directory if @runner.respond_to?(:reload_worker_directory)
242
- end
55
+ @conf.configure do |c|
56
+ if @stdout || @stderr
57
+ c.stdout_redirect @stdout, @stderr, @append
58
+ end
243
59
 
244
- def phased_restart
245
- unless @runner.respond_to?(:phased_restart) and @runner.phased_restart
246
- log "* phased-restart called but not available, restarting normally."
247
- return restart
60
+ if @control_url
61
+ c.activate_control_app @control_url, @control_options
62
+ end
248
63
  end
249
- true
250
- end
251
64
 
252
- def redirect_io
253
- @runner.redirect_io
65
+ @launcher = Puma::Launcher.new(@conf, :events => @events, :argv => argv)
254
66
  end
255
67
 
256
- def stats
257
- @runner.stats
258
- end
68
+ attr_reader :launcher
259
69
 
260
- def halt
261
- @status = :halt
262
- @runner.halt
70
+ # Parse the options, load the rackup, start the server and wait
71
+ # for it to finish.
72
+ #
73
+ def run
74
+ @launcher.run
263
75
  end
264
76
 
265
77
  private
266
- def title
267
- buffer = "puma #{Puma::Const::VERSION} (#{@options[:binds].join(',')})"
268
- buffer << " [#{@options[:tag]}]" if @options[:tag] && !@options[:tag].empty?
269
- buffer
270
- end
271
-
272
78
  def unsupported(str)
273
79
  @events.error(str)
274
80
  raise UnsupportedOption
275
81
  end
276
82
 
277
- def restart_args
278
- cmd = @options[:restart_cmd]
279
- if cmd
280
- cmd.split(' ') + @original_argv
281
- else
282
- @restart_argv
283
- end
284
- end
285
-
286
- def set_process_title
287
- Process.respond_to?(:setproctitle) ? Process.setproctitle(title) : $0 = title
288
- end
289
-
290
- def find_config
291
- if @cli_options[:config_file] == '-'
292
- @cli_options[:config_file] = nil
293
- else
294
- @cli_options[:config_file] ||= %W(config/puma/#{env}.rb config/puma.rb).find { |f| File.exist?(f) }
295
- end
296
- end
297
-
298
83
  # Build the OptionParser object to handle the available options.
299
84
  #
300
85
 
301
86
  def setup_options
302
- @cli_options = {}
303
- @options = {}
304
-
305
- @parser = OptionParser.new do |o|
306
- o.on "-b", "--bind URI", "URI to bind to (tcp://, unix://, ssl://)" do |arg|
307
- (@cli_options[:binds] ||= []) << arg
308
- end
309
-
310
- o.on "-C", "--config PATH", "Load PATH as a config file" do |arg|
311
- @cli_options[:config_file] = arg
312
- end
313
-
314
- o.on "--control URL", "The bind url to use for the control server",
315
- "Use 'auto' to use temp unix server" do |arg|
316
- if arg
317
- @cli_options[:control_url] = arg
318
- elsif jruby?
319
- unsupported "No default url available on JRuby"
87
+ @conf = Configuration.new do |c|
88
+ @parser = OptionParser.new do |o|
89
+ o.on "-b", "--bind URI", "URI to bind to (tcp://, unix://, ssl://)" do |arg|
90
+ c.bind arg
320
91
  end
321
- end
322
92
 
323
- o.on "--control-token TOKEN",
324
- "The token to use as authentication for the control server" do |arg|
325
- @cli_options[:control_auth_token] = arg
326
- end
327
-
328
- o.on "-d", "--daemon", "Daemonize the server into the background" do
329
- @cli_options[:daemon] = true
330
- @cli_options[:quiet] = true
331
- end
332
-
333
- o.on "--debug", "Log lowlevel debugging information" do
334
- @cli_options[:debug] = true
335
- end
336
-
337
- o.on "--dir DIR", "Change to DIR before starting" do |d|
338
- @cli_options[:directory] = d.to_s
339
- @cli_options[:worker_directory] = d.to_s
340
- end
341
-
342
- o.on "-e", "--environment ENVIRONMENT",
343
- "The environment to run the Rack app on (default development)" do |arg|
344
- @cli_options[:environment] = arg
345
- end
346
-
347
- o.on "-I", "--include PATH", "Specify $LOAD_PATH directories" do |arg|
348
- $LOAD_PATH.unshift(*arg.split(':'))
349
- end
350
-
351
- o.on "-p", "--port PORT", "Define the TCP port to bind to",
352
- "Use -b for more advanced options" do |arg|
353
- binds = (@cli_options[:binds] ||= [])
354
- binds << "tcp://#{Configuration::DefaultTCPHost}:#{arg}"
355
- end
356
-
357
- o.on "--pidfile PATH", "Use PATH as a pidfile" do |arg|
358
- @cli_options[:pidfile] = arg
359
- end
360
-
361
- o.on "--preload", "Preload the app. Cluster mode only" do
362
- @cli_options[:preload_app] = true
363
- end
364
-
365
- o.on "--prune-bundler", "Prune out the bundler env if possible" do
366
- @cli_options[:prune_bundler] = true
367
- end
368
-
369
- o.on "-q", "--quiet", "Quiet down the output" do
370
- @cli_options[:quiet] = true
371
- end
93
+ o.on "-C", "--config PATH", "Load PATH as a config file" do |arg|
94
+ c.load arg
95
+ end
372
96
 
373
- o.on "-R", "--restart-cmd CMD",
374
- "The puma command to run during a hot restart",
375
- "Default: inferred" do |cmd|
376
- @cli_options[:restart_cmd] = cmd
377
- end
97
+ o.on "--control URL", "The bind url to use for the control server",
98
+ "Use 'auto' to use temp unix server" do |arg|
99
+ if arg
100
+ @control_url = arg
101
+ elsif Puma.jruby?
102
+ unsupported "No default url available on JRuby"
103
+ end
104
+ end
378
105
 
379
- o.on "-S", "--state PATH", "Where to store the state details" do |arg|
380
- @cli_options[:state] = arg
381
- end
106
+ o.on "--control-token TOKEN",
107
+ "The token to use as authentication for the control server" do |arg|
108
+ @control_options[:auth_token] = arg
109
+ end
382
110
 
383
- o.on '-t', '--threads INT', "min:max threads to use (default 0:16)" do |arg|
384
- min, max = arg.split(":")
385
- if max
386
- @cli_options[:min_threads] = min
387
- @cli_options[:max_threads] = max
388
- else
389
- @cli_options[:min_threads] = 0
390
- @cli_options[:max_threads] = arg
111
+ o.on "-d", "--daemon", "Daemonize the server into the background" do
112
+ c.daemonize
113
+ c.quiet
391
114
  end
392
- end
393
115
 
394
- o.on "--tcp-mode", "Run the app in raw TCP mode instead of HTTP mode" do
395
- @cli_options[:mode] = :tcp
396
- end
116
+ o.on "--debug", "Log lowlevel debugging information" do
117
+ c.debug
118
+ end
397
119
 
398
- o.on "-V", "--version", "Print the version information" do
399
- puts "puma version #{Puma::Const::VERSION}"
400
- exit 0
401
- end
120
+ o.on "--dir DIR", "Change to DIR before starting" do |d|
121
+ c.directory d
122
+ end
402
123
 
403
- o.on "-w", "--workers COUNT",
404
- "Activate cluster mode: How many worker processes to create" do |arg|
405
- @cli_options[:workers] = arg.to_i
406
- end
124
+ o.on "-e", "--environment ENVIRONMENT",
125
+ "The environment to run the Rack app on (default development)" do |arg|
126
+ c.environment arg
127
+ end
407
128
 
408
- o.on "--tag NAME", "Additional text to display in process listing" do |arg|
409
- @cli_options[:tag] = arg
410
- end
129
+ o.on "-I", "--include PATH", "Specify $LOAD_PATH directories" do |arg|
130
+ $LOAD_PATH.unshift(*arg.split(':'))
131
+ end
411
132
 
412
- o.on "--redirect-stdout FILE", "Redirect STDOUT to a specific file" do |arg|
413
- @cli_options[:redirect_stdout] = arg
414
- end
133
+ o.on "-p", "--port PORT", "Define the TCP port to bind to",
134
+ "Use -b for more advanced options" do |arg|
135
+ c.bind "tcp://#{Configuration::DefaultTCPHost}:#{arg}"
136
+ end
415
137
 
416
- o.on "--redirect-stderr FILE", "Redirect STDERR to a specific file" do |arg|
417
- @cli_options[:redirect_stderr] = arg
418
- end
138
+ o.on "--pidfile PATH", "Use PATH as a pidfile" do |arg|
139
+ c.pidfile arg
140
+ end
419
141
 
420
- o.on "--[no-]redirect-append", "Append to redirected files" do |val|
421
- @cli_options[:redirect_append] = val
422
- end
142
+ o.on "--preload", "Preload the app. Cluster mode only" do
143
+ c.preload_app!
144
+ end
423
145
 
424
- o.banner = "puma <options> <rackup file>"
146
+ o.on "--prune-bundler", "Prune out the bundler env if possible" do
147
+ c.prune_bundler
148
+ end
425
149
 
426
- o.on_tail "-h", "--help", "Show help" do
427
- log o
428
- exit 0
429
- end
430
- end
431
- end
150
+ o.on "-q", "--quiet", "Do not log requests internally (default true)" do
151
+ c.quiet
152
+ end
432
153
 
433
- def generate_restart_data
434
- # Use the same trick as unicorn, namely favor PWD because
435
- # it will contain an unresolved symlink, useful for when
436
- # the pwd is /data/releases/current.
437
- if dir = ENV['PWD']
438
- s_env = File.stat(dir)
439
- s_pwd = File.stat(Dir.pwd)
440
-
441
- if s_env.ino == s_pwd.ino and (jruby? or s_env.dev == s_pwd.dev)
442
- @restart_dir = dir
443
- @options[:worker_directory] = dir
444
- end
445
- end
154
+ o.on "-v", "--log-requests", "Log requests as they occur" do
155
+ c.log_requests
156
+ end
446
157
 
447
- @restart_dir ||= Dir.pwd
158
+ o.on "-R", "--restart-cmd CMD",
159
+ "The puma command to run during a hot restart",
160
+ "Default: inferred" do |cmd|
161
+ c.restart_command cmd
162
+ end
448
163
 
449
- @original_argv = @argv.dup
164
+ o.on "-S", "--state PATH", "Where to store the state details" do |arg|
165
+ c.state_path arg
166
+ end
450
167
 
451
- require 'rubygems'
168
+ o.on '-t', '--threads INT', "min:max threads to use (default 0:16)" do |arg|
169
+ min, max = arg.split(":")
170
+ if max
171
+ c.threads min, max
172
+ else
173
+ c.threads 0, max
174
+ end
175
+ end
452
176
 
453
- # if $0 is a file in the current directory, then restart
454
- # it the same, otherwise add -S on there because it was
455
- # picked up in PATH.
456
- #
457
- if File.exist?($0)
458
- arg0 = [Gem.ruby, $0]
459
- else
460
- arg0 = [Gem.ruby, "-S", $0]
461
- end
177
+ o.on "--tcp-mode", "Run the app in raw TCP mode instead of HTTP mode" do
178
+ c.tcp_mode!
179
+ end
462
180
 
463
- # Detect and reinject -Ilib from the command line
464
- lib = File.expand_path "lib"
465
- arg0[1,0] = ["-I", lib] if $:[0] == lib
181
+ o.on "-V", "--version", "Print the version information" do
182
+ puts "puma version #{Puma::Const::VERSION}"
183
+ exit 0
184
+ end
466
185
 
467
- if defined? Puma::WILD_ARGS
468
- @restart_argv = arg0 + Puma::WILD_ARGS + @original_argv
469
- else
470
- @restart_argv = arg0 + @original_argv
471
- end
472
- end
186
+ o.on "-w", "--workers COUNT",
187
+ "Activate cluster mode: How many worker processes to create" do |arg|
188
+ c.workers arg
189
+ end
473
190
 
474
- def set_rack_environment
475
- @options[:environment] = env
476
- ENV['RACK_ENV'] = env
477
- end
191
+ o.on "--tag NAME", "Additional text to display in process listing" do |arg|
192
+ c.tag arg
193
+ end
478
194
 
479
- def setup_signals
480
- begin
481
- Signal.trap "SIGUSR2" do
482
- restart
483
- end
484
- rescue Exception
485
- log "*** SIGUSR2 not implemented, signal based restart unavailable!"
486
- end
195
+ o.on "--redirect-stdout FILE", "Redirect STDOUT to a specific file" do |arg|
196
+ @stdout = arg.to_s
197
+ end
487
198
 
488
- begin
489
- Signal.trap "SIGUSR1" do
490
- phased_restart
491
- end
492
- rescue Exception
493
- log "*** SIGUSR1 not implemented, signal based restart unavailable!"
494
- end
199
+ o.on "--redirect-stderr FILE", "Redirect STDERR to a specific file" do |arg|
200
+ @stderr = arg.to_s
201
+ end
495
202
 
496
- begin
497
- Signal.trap "SIGTERM" do
498
- stop
499
- end
500
- rescue Exception
501
- log "*** SIGTERM not implemented, signal based gracefully stopping unavailable!"
502
- end
203
+ o.on "--[no-]redirect-append", "Append to redirected files" do |val|
204
+ @append = val
205
+ end
503
206
 
504
- begin
505
- Signal.trap "SIGHUP" do
506
- redirect_io
507
- end
508
- rescue Exception
509
- log "*** SIGHUP not implemented, signal based logs reopening unavailable!"
510
- end
207
+ o.banner = "puma <options> <rackup file>"
511
208
 
512
- if jruby?
513
- Signal.trap("INT") do
514
- @status = :exit
515
- graceful_stop
516
- exit
209
+ o.on_tail "-h", "--help", "Show help" do
210
+ $stdout.puts o
211
+ exit 0
212
+ end
517
213
  end
518
214
  end
519
215
  end
520
-
521
- def close_binder_listeners
522
- @binder.listeners.each do |l, io|
523
- io.close
524
- uri = URI.parse(l)
525
- next unless uri.scheme == 'unix'
526
- File.unlink("#{uri.host}#{uri.path}")
527
- end
528
- end
529
-
530
- def parse_options
531
- @parser.parse! @argv
532
-
533
- @cli_options[:rackup] = @argv.shift if @argv.last
534
-
535
- find_config
536
-
537
- @config = Puma::Configuration.new @cli_options
538
-
539
- # Advertise the Configuration
540
- Puma.cli_config = @config
541
-
542
- @config.load
543
-
544
- @options = @config.options
545
-
546
- if clustered? && (jruby? || windows?)
547
- unsupported 'worker mode not supported on JRuby or Windows'
548
- end
549
-
550
- if @options[:daemon] && windows?
551
- unsupported 'daemon mode not supported on Windows'
552
- end
553
- end
554
-
555
- def prune_bundler
556
- return unless defined?(Bundler)
557
- puma = Bundler.rubygems.loaded_specs("puma")
558
- dirs = puma.require_paths.map { |x| File.join(puma.full_gem_path, x) }
559
- puma_lib_dir = dirs.detect { |x| File.exist? File.join(x, '../bin/puma-wild') }
560
-
561
- unless puma_lib_dir
562
- log "! Unable to prune Bundler environment, continuing"
563
- return
564
- end
565
-
566
- deps = puma.runtime_dependencies.map do |d|
567
- spec = Bundler.rubygems.loaded_specs(d.name)
568
- "#{d.name}:#{spec.version.to_s}"
569
- end
570
-
571
- log '* Pruning Bundler environment'
572
- home = ENV['GEM_HOME']
573
- Bundler.with_clean_env do
574
- ENV['GEM_HOME'] = home
575
- ENV['PUMA_BUNDLER_PRUNED'] = '1'
576
- wild = File.expand_path(File.join(puma_lib_dir, "../bin/puma-wild"))
577
- args = [Gem.ruby, wild, '-I', dirs.join(':'), deps.join(',')] + @original_argv
578
- Kernel.exec(*args)
579
- end
580
- end
581
216
  end
582
217
  end