jun-puma 1.0.0-java → 1.0.1-java
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.
- checksums.yaml +4 -4
- data/History.md +14 -63
- data/README.md +22 -73
- data/docs/fork_worker.md +1 -5
- data/docs/restart.md +0 -1
- data/docs/signals.md +2 -2
- data/docs/systemd.md +1 -10
- data/ext/puma_http11/extconf.rb +18 -22
- data/ext/puma_http11/mini_ssl.c +2 -12
- data/ext/puma_http11/org/jruby/puma/Http11.java +0 -2
- data/ext/puma_http11/org/jruby/puma/MiniSSL.java +1 -2
- data/ext/puma_http11/puma_http11.c +0 -3
- data/lib/puma/binder.rb +4 -5
- data/lib/puma/cli.rb +5 -9
- data/lib/puma/client.rb +10 -60
- data/lib/puma/cluster/worker.rb +6 -4
- data/lib/puma/cluster/worker_handle.rb +5 -4
- data/lib/puma/cluster.rb +9 -63
- data/lib/puma/configuration.rb +18 -17
- data/lib/puma/const.rb +2 -20
- data/lib/puma/control_cli.rb +4 -4
- data/lib/puma/dsl.rb +34 -255
- data/lib/puma/error_logger.rb +4 -4
- data/lib/puma/jruby_restart.rb +16 -0
- data/lib/puma/launcher.rb +3 -7
- data/lib/puma/log_writer.rb +9 -9
- data/lib/puma/minissl/context_builder.rb +0 -1
- data/lib/puma/minissl.rb +0 -1
- data/lib/puma/null_io.rb +2 -25
- data/lib/puma/puma_http11.jar +0 -0
- data/lib/puma/request.rb +6 -23
- data/lib/puma/runner.rb +1 -1
- data/lib/puma/server.rb +19 -35
- data/lib/puma/state_file.rb +2 -2
- data/lib/puma/util.rb +1 -1
- data/lib/rack/handler/puma.rb +3 -6
- metadata +8 -8
data/lib/puma/dsl.rb
CHANGED
@@ -51,8 +51,7 @@ module Puma
|
|
51
51
|
class DSL
|
52
52
|
ON_WORKER_KEY = [String, Symbol].freeze
|
53
53
|
|
54
|
-
#
|
55
|
-
#
|
54
|
+
# convenience method so logic can be used in CI
|
56
55
|
# @see ssl_bind
|
57
56
|
#
|
58
57
|
def self.ssl_bind_str(host, port, opts)
|
@@ -86,7 +85,6 @@ module Puma
|
|
86
85
|
"&verify_mode=#{verify}#{tls_str}#{ca_additions}#{backlog_str}"
|
87
86
|
else
|
88
87
|
ssl_cipher_filter = opts[:ssl_cipher_filter] ? "&ssl_cipher_filter=#{opts[:ssl_cipher_filter]}" : nil
|
89
|
-
ssl_ciphersuites = opts[:ssl_ciphersuites] ? "&ssl_ciphersuites=#{opts[:ssl_ciphersuites]}" : nil
|
90
88
|
v_flags = (ary = opts[:verification_flags]) ? "&verification_flags=#{Array(ary).join ','}" : nil
|
91
89
|
|
92
90
|
cert_flags = (cert = opts[:cert]) ? "cert=#{Puma::Util.escape(cert)}" : nil
|
@@ -117,7 +115,7 @@ module Puma
|
|
117
115
|
nil
|
118
116
|
end
|
119
117
|
|
120
|
-
"ssl://#{host}:#{port}?#{cert_flags}#{key_flags}#{password_flags}#{ssl_cipher_filter}
|
118
|
+
"ssl://#{host}:#{port}?#{cert_flags}#{key_flags}#{password_flags}#{ssl_cipher_filter}" \
|
121
119
|
"#{reuse_flag}&verify_mode=#{verify}#{tls_str}#{ca_additions}#{v_flags}#{backlog_str}#{low_latency_str}"
|
122
120
|
end
|
123
121
|
end
|
@@ -165,10 +163,7 @@ module Puma
|
|
165
163
|
@options[key.to_sym] || default
|
166
164
|
end
|
167
165
|
|
168
|
-
# Load the named plugin for use by this configuration
|
169
|
-
#
|
170
|
-
# @example
|
171
|
-
# plugin :tmp_restart
|
166
|
+
# Load the named plugin for use by this configuration
|
172
167
|
#
|
173
168
|
def plugin(name)
|
174
169
|
@plugins << @config.load_plugin(name)
|
@@ -215,7 +210,6 @@ module Puma
|
|
215
210
|
# activate_control_app 'unix:///var/run/pumactl.sock', { auth_token: '12345' }
|
216
211
|
# @example
|
217
212
|
# activate_control_app 'unix:///var/run/pumactl.sock', { no_token: true }
|
218
|
-
#
|
219
213
|
def activate_control_app(url="auto", opts={})
|
220
214
|
if url == "auto"
|
221
215
|
path = Configuration.temp_path
|
@@ -241,12 +235,8 @@ module Puma
|
|
241
235
|
@options[:control_url_umask] = opts[:umask] if opts[:umask]
|
242
236
|
end
|
243
237
|
|
244
|
-
# Load additional configuration from a file
|
245
|
-
# Files get loaded later via Configuration#load
|
246
|
-
#
|
247
|
-
# @example
|
248
|
-
# load 'config/puma/production.rb'
|
249
|
-
#
|
238
|
+
# Load additional configuration from a file
|
239
|
+
# Files get loaded later via Configuration#load
|
250
240
|
def load(file)
|
251
241
|
@options[:config_files] ||= []
|
252
242
|
@options[:config_files] << file
|
@@ -278,7 +268,6 @@ module Puma
|
|
278
268
|
# bind 'tcp://0.0.0.0:9292?low_latency=false'
|
279
269
|
# @example Socket permissions
|
280
270
|
# bind 'unix:///var/run/puma.sock?umask=0111'
|
281
|
-
#
|
282
271
|
# @see Puma::Runner#load_and_bind
|
283
272
|
# @see Puma::Cluster#run
|
284
273
|
#
|
@@ -313,70 +302,39 @@ module Puma
|
|
313
302
|
#
|
314
303
|
# @example Only bind to systemd activated sockets, ignoring other binds
|
315
304
|
# bind_to_activated_sockets 'only'
|
316
|
-
#
|
317
305
|
def bind_to_activated_sockets(bind=true)
|
318
306
|
@options[:bind_to_activated_sockets] = bind
|
319
307
|
end
|
320
308
|
|
321
|
-
# Define the TCP port to bind to. Use
|
322
|
-
#
|
323
|
-
# The default is +9292+.
|
309
|
+
# Define the TCP port to bind to. Use +bind+ for more advanced options.
|
324
310
|
#
|
325
311
|
# @example
|
326
|
-
# port
|
327
|
-
#
|
312
|
+
# port 9292
|
328
313
|
def port(port, host=nil)
|
329
314
|
host ||= default_host
|
330
315
|
bind URI::Generic.build(scheme: 'tcp', host: host, port: Integer(port)).to_s
|
331
316
|
end
|
332
317
|
|
333
318
|
# Define how long the tcp socket stays open, if no data has been received.
|
334
|
-
#
|
335
|
-
# The default is 30 seconds.
|
336
|
-
#
|
337
|
-
# @example
|
338
|
-
# first_data_timeout 40
|
339
|
-
#
|
340
319
|
# @see Puma::Server.new
|
341
|
-
#
|
342
320
|
def first_data_timeout(seconds)
|
343
321
|
@options[:first_data_timeout] = Integer(seconds)
|
344
322
|
end
|
345
323
|
|
346
324
|
# Define how long persistent connections can be idle before Puma closes them.
|
347
|
-
#
|
348
|
-
# The default is 20 seconds.
|
349
|
-
#
|
350
|
-
# @example
|
351
|
-
# persistent_timeout 30
|
352
|
-
#
|
353
325
|
# @see Puma::Server.new
|
354
|
-
#
|
355
326
|
def persistent_timeout(seconds)
|
356
327
|
@options[:persistent_timeout] = Integer(seconds)
|
357
328
|
end
|
358
329
|
|
359
330
|
# If a new request is not received within this number of seconds, begin shutting down.
|
360
|
-
#
|
361
|
-
# The default is +nil+.
|
362
|
-
#
|
363
|
-
# @example
|
364
|
-
# idle_timeout 60
|
365
|
-
#
|
366
331
|
# @see Puma::Server.new
|
367
|
-
#
|
368
332
|
def idle_timeout(seconds)
|
369
333
|
@options[:idle_timeout] = Integer(seconds)
|
370
334
|
end
|
371
335
|
|
372
336
|
# Work around leaky apps that leave garbage in Thread locals
|
373
337
|
# across requests.
|
374
|
-
#
|
375
|
-
# The default is +false+.
|
376
|
-
#
|
377
|
-
# @example
|
378
|
-
# clean_thread_locals
|
379
|
-
#
|
380
338
|
def clean_thread_locals(which=true)
|
381
339
|
@options[:clean_thread_locals] = which
|
382
340
|
end
|
@@ -384,7 +342,6 @@ module Puma
|
|
384
342
|
# When shutting down, drain the accept socket of pending connections and
|
385
343
|
# process them. This loops over the accept socket until there are no more
|
386
344
|
# read events and then stops looking and waits for the requests to finish.
|
387
|
-
#
|
388
345
|
# @see Puma::Server#graceful_shutdown
|
389
346
|
#
|
390
347
|
def drain_on_shutdown(which=true)
|
@@ -398,22 +355,18 @@ module Puma
|
|
398
355
|
#
|
399
356
|
# @example
|
400
357
|
# environment 'production'
|
401
|
-
#
|
402
358
|
def environment(environment)
|
403
359
|
@options[:environment] = environment
|
404
360
|
end
|
405
361
|
|
406
|
-
# How long to wait for threads to stop when shutting them
|
407
|
-
# Specifying :immediately will cause
|
408
|
-
#
|
362
|
+
# How long to wait for threads to stop when shutting them
|
363
|
+
# down. Defaults to :forever. Specifying :immediately will cause
|
364
|
+
# Puma to kill the threads immediately. Otherwise the value
|
365
|
+
# is the number of seconds to wait.
|
409
366
|
#
|
410
367
|
# Puma always waits a few seconds after killing a thread for it to try
|
411
368
|
# to finish up it's work, even in :immediately mode.
|
412
|
-
#
|
413
|
-
# The default is +:forever+.
|
414
|
-
#
|
415
369
|
# @see Puma::Server#graceful_shutdown
|
416
|
-
#
|
417
370
|
def force_shutdown_after(val=:forever)
|
418
371
|
i = case val
|
419
372
|
when :forever
|
@@ -436,7 +389,6 @@ module Puma
|
|
436
389
|
# on_restart do
|
437
390
|
# puts 'On restart...'
|
438
391
|
# end
|
439
|
-
#
|
440
392
|
def on_restart(&block)
|
441
393
|
@options[:on_restart] ||= []
|
442
394
|
@options[:on_restart] << block
|
@@ -448,7 +400,6 @@ module Puma
|
|
448
400
|
#
|
449
401
|
# @example
|
450
402
|
# restart_command '/u/app/lolcat/bin/restart_puma'
|
451
|
-
#
|
452
403
|
def restart_command(cmd)
|
453
404
|
@options[:restart_cmd] = cmd.to_s
|
454
405
|
end
|
@@ -457,49 +408,31 @@ module Puma
|
|
457
408
|
#
|
458
409
|
# @example
|
459
410
|
# pidfile '/u/apps/lolcat/tmp/pids/puma.pid'
|
460
|
-
#
|
461
411
|
def pidfile(path)
|
462
412
|
@options[:pidfile] = path.to_s
|
463
413
|
end
|
464
414
|
|
465
|
-
# Disable request logging,
|
466
|
-
#
|
467
|
-
# The default is +true+.
|
415
|
+
# Disable request logging, if this isn't used it'll be enabled by default.
|
468
416
|
#
|
469
417
|
# @example
|
470
418
|
# quiet
|
471
|
-
#
|
472
419
|
def quiet(which=true)
|
473
420
|
@options[:log_requests] = !which
|
474
421
|
end
|
475
422
|
|
476
|
-
# Enable request logging
|
477
|
-
#
|
478
|
-
# The default is +false+.
|
479
|
-
#
|
480
|
-
# @example
|
481
|
-
# log_requests
|
423
|
+
# Enable request logging
|
482
424
|
#
|
483
425
|
def log_requests(which=true)
|
484
426
|
@options[:log_requests] = which
|
485
427
|
end
|
486
428
|
|
487
429
|
# Pass in a custom logging class instance
|
488
|
-
#
|
489
|
-
# @example
|
490
|
-
# custom_logger Logger.new('t.log')
|
491
|
-
#
|
492
430
|
def custom_logger(custom_logger)
|
493
431
|
@options[:custom_logger] = custom_logger
|
494
432
|
end
|
495
433
|
|
496
434
|
# Show debugging info
|
497
435
|
#
|
498
|
-
# The default is +false+.
|
499
|
-
#
|
500
|
-
# @example
|
501
|
-
# debug
|
502
|
-
#
|
503
436
|
def debug
|
504
437
|
@options[:debug] = true
|
505
438
|
end
|
@@ -510,7 +443,6 @@ module Puma
|
|
510
443
|
#
|
511
444
|
# @example
|
512
445
|
# rackup '/u/apps/lolcat/config.ru'
|
513
|
-
#
|
514
446
|
def rackup(path)
|
515
447
|
@options[:rackup] ||= path.to_s
|
516
448
|
end
|
@@ -518,32 +450,21 @@ module Puma
|
|
518
450
|
# Allows setting `env['rack.url_scheme']`.
|
519
451
|
# Only necessary if X-Forwarded-Proto is not being set by your proxy
|
520
452
|
# Normal values are 'http' or 'https'.
|
521
|
-
#
|
522
453
|
def rack_url_scheme(scheme=nil)
|
523
454
|
@options[:rack_url_scheme] = scheme
|
524
455
|
end
|
525
456
|
|
526
|
-
# Enable HTTP 103 Early Hints responses.
|
527
|
-
#
|
528
|
-
# The default is +nil+.
|
529
|
-
#
|
530
|
-
# @example
|
531
|
-
# early_hints
|
532
|
-
#
|
533
457
|
def early_hints(answer=true)
|
534
458
|
@options[:early_hints] = answer
|
535
459
|
end
|
536
460
|
|
537
461
|
# Redirect +STDOUT+ and +STDERR+ to files specified. The +append+ parameter
|
538
|
-
# specifies whether the output is appended
|
539
|
-
#
|
540
|
-
# The default is +false+.
|
462
|
+
# specifies whether the output is appended, the default is +false+.
|
541
463
|
#
|
542
464
|
# @example
|
543
465
|
# stdout_redirect '/app/lolcat/log/stdout', '/app/lolcat/log/stderr'
|
544
466
|
# @example
|
545
467
|
# stdout_redirect '/app/lolcat/log/stdout', '/app/lolcat/log/stderr', true
|
546
|
-
#
|
547
468
|
def stdout_redirect(stdout=nil, stderr=nil, append=false)
|
548
469
|
@options[:redirect_stdout] = stdout
|
549
470
|
@options[:redirect_stderr] = stderr
|
@@ -554,9 +475,8 @@ module Puma
|
|
554
475
|
@options[:log_formatter] = block
|
555
476
|
end
|
556
477
|
|
557
|
-
# Configure the number of threads to use to answer
|
558
|
-
#
|
559
|
-
# It can be a single fixed number, or a +min+ and a +max+.
|
478
|
+
# Configure +min+ to be the minimum number of threads to use to answer
|
479
|
+
# requests and +max+ the maximum.
|
560
480
|
#
|
561
481
|
# The default is the environment variables +PUMA_MIN_THREADS+ / +PUMA_MAX_THREADS+
|
562
482
|
# (or +MIN_THREADS+ / +MAX_THREADS+ if the +PUMA_+ variables aren't set).
|
@@ -564,13 +484,10 @@ module Puma
|
|
564
484
|
# If these environment variables aren't set, the default is "0, 5" in MRI or "0, 16" for other interpreters.
|
565
485
|
#
|
566
486
|
# @example
|
567
|
-
# threads 5
|
568
|
-
# @example
|
569
487
|
# threads 0, 16
|
570
488
|
# @example
|
571
489
|
# threads 5, 5
|
572
|
-
|
573
|
-
def threads(min, max = min)
|
490
|
+
def threads(min, max)
|
574
491
|
min = Integer(min)
|
575
492
|
max = Integer(max)
|
576
493
|
if min > max
|
@@ -610,7 +527,6 @@ module Puma
|
|
610
527
|
# cert: path_to_cert,
|
611
528
|
# key: path_to_key,
|
612
529
|
# ssl_cipher_filter: cipher_filter, # optional
|
613
|
-
# ssl_ciphersuites: ciphersuites, # optional
|
614
530
|
# verify_mode: verify_mode, # default 'none'
|
615
531
|
# verification_flags: flags, # optional, not supported by JRuby
|
616
532
|
# reuse: true # optional
|
@@ -633,7 +549,6 @@ module Puma
|
|
633
549
|
# ssl_cipher_list: cipher_list, # optional
|
634
550
|
# verify_mode: verify_mode # default 'none'
|
635
551
|
# }
|
636
|
-
#
|
637
552
|
def ssl_bind(host, port, opts = {})
|
638
553
|
add_pem_values_to_options_store(opts)
|
639
554
|
bind self.class.ssl_bind_str(host, port, opts)
|
@@ -644,7 +559,6 @@ module Puma
|
|
644
559
|
#
|
645
560
|
# @example
|
646
561
|
# state_path '/u/apps/lolcat/tmp/pids/puma.state'
|
647
|
-
#
|
648
562
|
def state_path(path)
|
649
563
|
@options[:state] = path.to_s
|
650
564
|
end
|
@@ -653,7 +567,6 @@ module Puma
|
|
653
567
|
#
|
654
568
|
# @example
|
655
569
|
# state_permission 0600
|
656
|
-
#
|
657
570
|
# @version 5.0.0
|
658
571
|
#
|
659
572
|
def state_permission(permission)
|
@@ -667,12 +580,7 @@ module Puma
|
|
667
580
|
# set, otherwise 0.
|
668
581
|
#
|
669
582
|
# @note Cluster mode only.
|
670
|
-
#
|
671
|
-
# @example
|
672
|
-
# workers 2
|
673
|
-
#
|
674
583
|
# @see Puma::Cluster
|
675
|
-
#
|
676
584
|
def workers(count)
|
677
585
|
@options[:workers] = count.to_i
|
678
586
|
end
|
@@ -690,24 +598,12 @@ module Puma
|
|
690
598
|
#
|
691
599
|
# Moving from workers = 1 to workers = 0 will save 10-30% of memory use.
|
692
600
|
#
|
693
|
-
# The default is +false+.
|
694
|
-
#
|
695
601
|
# @note Cluster mode only.
|
696
|
-
#
|
697
|
-
# @example
|
698
|
-
# silence_single_worker_warning
|
699
|
-
#
|
700
602
|
def silence_single_worker_warning
|
701
603
|
@options[:silence_single_worker_warning] = true
|
702
604
|
end
|
703
605
|
|
704
606
|
# Disable warning message when running single mode with callback hook defined.
|
705
|
-
#
|
706
|
-
# The default is +false+.
|
707
|
-
#
|
708
|
-
# @example
|
709
|
-
# silence_fork_callback_warning
|
710
|
-
#
|
711
607
|
def silence_fork_callback_warning
|
712
608
|
@options[:silence_fork_callback_warning] = true
|
713
609
|
end
|
@@ -722,12 +618,10 @@ module Puma
|
|
722
618
|
# This can be called multiple times to add several hooks.
|
723
619
|
#
|
724
620
|
# @note Cluster mode only.
|
725
|
-
#
|
726
621
|
# @example
|
727
622
|
# before_fork do
|
728
623
|
# puts "Starting workers..."
|
729
624
|
# end
|
730
|
-
#
|
731
625
|
def before_fork(&block)
|
732
626
|
warn_if_in_single_mode('before_fork')
|
733
627
|
|
@@ -741,12 +635,10 @@ module Puma
|
|
741
635
|
# This can be called multiple times to add several hooks.
|
742
636
|
#
|
743
637
|
# @note Cluster mode only.
|
744
|
-
#
|
745
638
|
# @example
|
746
639
|
# on_worker_boot do
|
747
640
|
# puts 'Before worker boot...'
|
748
641
|
# end
|
749
|
-
#
|
750
642
|
def on_worker_boot(key = nil, &block)
|
751
643
|
warn_if_in_single_mode('on_worker_boot')
|
752
644
|
|
@@ -754,20 +646,17 @@ module Puma
|
|
754
646
|
end
|
755
647
|
|
756
648
|
# Code to run immediately before a worker shuts
|
757
|
-
# down (after it has finished processing HTTP requests).
|
758
|
-
# index is passed as an argument. These hooks
|
649
|
+
# down (after it has finished processing HTTP requests). These hooks
|
759
650
|
# can block if necessary to wait for background operations unknown
|
760
651
|
# to Puma to finish before the process terminates.
|
761
652
|
#
|
762
653
|
# This can be called multiple times to add several hooks.
|
763
654
|
#
|
764
655
|
# @note Cluster mode only.
|
765
|
-
#
|
766
656
|
# @example
|
767
657
|
# on_worker_shutdown do
|
768
658
|
# puts 'On worker shutdown...'
|
769
659
|
# end
|
770
|
-
#
|
771
660
|
def on_worker_shutdown(key = nil, &block)
|
772
661
|
warn_if_in_single_mode('on_worker_shutdown')
|
773
662
|
|
@@ -780,12 +669,10 @@ module Puma
|
|
780
669
|
# This can be called multiple times to add several hooks.
|
781
670
|
#
|
782
671
|
# @note Cluster mode only.
|
783
|
-
#
|
784
672
|
# @example
|
785
673
|
# on_worker_fork do
|
786
674
|
# puts 'Before worker fork...'
|
787
675
|
# end
|
788
|
-
#
|
789
676
|
def on_worker_fork(&block)
|
790
677
|
warn_if_in_single_mode('on_worker_fork')
|
791
678
|
|
@@ -798,12 +685,10 @@ module Puma
|
|
798
685
|
# This is called everytime a worker is to be started.
|
799
686
|
#
|
800
687
|
# @note Cluster mode only.
|
801
|
-
#
|
802
688
|
# @example
|
803
689
|
# after_worker_fork do
|
804
690
|
# puts 'After worker fork...'
|
805
691
|
# end
|
806
|
-
#
|
807
692
|
def after_worker_fork(&block)
|
808
693
|
warn_if_in_single_mode('after_worker_fork')
|
809
694
|
|
@@ -818,22 +703,10 @@ module Puma
|
|
818
703
|
# on_booted do
|
819
704
|
# puts 'After booting...'
|
820
705
|
# end
|
821
|
-
#
|
822
706
|
def on_booted(&block)
|
823
707
|
@config.options[:events].on_booted(&block)
|
824
708
|
end
|
825
709
|
|
826
|
-
# Code to run after puma is stopped (works for both: single and clustered)
|
827
|
-
#
|
828
|
-
# @example
|
829
|
-
# on_stopped do
|
830
|
-
# puts 'After stopping...'
|
831
|
-
# end
|
832
|
-
#
|
833
|
-
def on_stopped(&block)
|
834
|
-
@config.options[:events].on_stopped(&block)
|
835
|
-
end
|
836
|
-
|
837
710
|
# When `fork_worker` is enabled, code to run in Worker 0
|
838
711
|
# before all other workers are re-forked from this process,
|
839
712
|
# after the server has temporarily stopped serving requests
|
@@ -846,12 +719,10 @@ module Puma
|
|
846
719
|
# This can be called multiple times to add several hooks.
|
847
720
|
#
|
848
721
|
# @note Cluster mode with `fork_worker` enabled only.
|
849
|
-
#
|
850
722
|
# @example
|
851
723
|
# on_refork do
|
852
724
|
# 3.times {GC.start}
|
853
725
|
# end
|
854
|
-
#
|
855
726
|
# @version 5.0.0
|
856
727
|
#
|
857
728
|
def on_refork(key = nil, &block)
|
@@ -874,7 +745,6 @@ module Puma
|
|
874
745
|
# on_thread_start do
|
875
746
|
# puts 'On thread start...'
|
876
747
|
# end
|
877
|
-
#
|
878
748
|
def on_thread_start(&block)
|
879
749
|
@options[:before_thread_start] ||= []
|
880
750
|
@options[:before_thread_start] << block
|
@@ -899,7 +769,6 @@ module Puma
|
|
899
769
|
# on_thread_exit do
|
900
770
|
# puts 'On thread exit...'
|
901
771
|
# end
|
902
|
-
#
|
903
772
|
def on_thread_exit(&block)
|
904
773
|
@options[:before_thread_exit] ||= []
|
905
774
|
@options[:before_thread_exit] << block
|
@@ -914,7 +783,6 @@ module Puma
|
|
914
783
|
# or scheduling asynchronous tasks to execute after a response.
|
915
784
|
#
|
916
785
|
# This can be called multiple times to add several hooks.
|
917
|
-
#
|
918
786
|
def out_of_band(&block)
|
919
787
|
process_hook :out_of_band, nil, block, 'out_of_band'
|
920
788
|
end
|
@@ -925,21 +793,16 @@ module Puma
|
|
925
793
|
#
|
926
794
|
# @example
|
927
795
|
# directory '/u/apps/lolcat'
|
928
|
-
#
|
929
796
|
def directory(dir)
|
930
797
|
@options[:directory] = dir.to_s
|
931
798
|
end
|
932
799
|
|
933
800
|
# Preload the application before starting the workers; this conflicts with
|
934
|
-
# phased restart feature.
|
935
|
-
#
|
936
|
-
# The default is +true+ if your app uses more than 1 worker.
|
801
|
+
# phased restart feature. On by default if your app uses more than 1 worker.
|
937
802
|
#
|
938
803
|
# @note Cluster mode only.
|
939
|
-
#
|
940
804
|
# @example
|
941
805
|
# preload_app!
|
942
|
-
#
|
943
806
|
def preload_app!(answer=true)
|
944
807
|
@options[:preload_app] = answer
|
945
808
|
end
|
@@ -951,7 +814,6 @@ module Puma
|
|
951
814
|
# lowlevel_error_handler do |err|
|
952
815
|
# [200, {}, ["error page"]]
|
953
816
|
# end
|
954
|
-
#
|
955
817
|
def lowlevel_error_handler(obj=nil, &block)
|
956
818
|
obj ||= block
|
957
819
|
raise "Provide either a #call'able or a block" unless obj
|
@@ -971,26 +833,23 @@ module Puma
|
|
971
833
|
# new Bundler context and thus can float around as the release
|
972
834
|
# dictates.
|
973
835
|
#
|
974
|
-
# @note This is incompatible with +preload_app!+.
|
975
|
-
# @note This is only supported for RubyGems 2.2+
|
976
|
-
#
|
977
836
|
# @see extra_runtime_dependencies
|
978
837
|
#
|
838
|
+
# @note This is incompatible with +preload_app!+.
|
839
|
+
# @note This is only supported for RubyGems 2.2+
|
979
840
|
def prune_bundler(answer=true)
|
980
841
|
@options[:prune_bundler] = answer
|
981
842
|
end
|
982
843
|
|
983
|
-
#
|
984
|
-
# SIGTERM is something expected, you can suppress these
|
844
|
+
# By default, Puma will raise SignalException when SIGTERM is received. In
|
845
|
+
# environments where SIGTERM is something expected, you can suppress these
|
846
|
+
# with this option.
|
985
847
|
#
|
986
848
|
# This can be useful for example in Kubernetes, where rolling restart is
|
987
|
-
# guaranteed usually on
|
988
|
-
#
|
989
|
-
# The default is +true+.
|
849
|
+
# guaranteed usually on infrastructure level.
|
990
850
|
#
|
991
851
|
# @example
|
992
852
|
# raise_exception_on_sigterm false
|
993
|
-
#
|
994
853
|
# @see Puma::Launcher#setup_signals
|
995
854
|
# @see Puma::Cluster#setup_signals
|
996
855
|
#
|
@@ -1009,7 +868,6 @@ module Puma
|
|
1009
868
|
# extra_runtime_dependencies ['gem_name_1', 'gem_name_2']
|
1010
869
|
# @example
|
1011
870
|
# extra_runtime_dependencies ['puma_worker_killer', 'puma-heroku']
|
1012
|
-
#
|
1013
871
|
# @see Puma::Launcher#extra_runtime_deps_directories
|
1014
872
|
#
|
1015
873
|
def extra_runtime_dependencies(answer = [])
|
@@ -1021,26 +879,21 @@ module Puma
|
|
1021
879
|
# If you do not specify a tag, Puma will infer it. If you do not want Puma
|
1022
880
|
# to add a tag, use an empty string.
|
1023
881
|
#
|
1024
|
-
# The default is the current file or directory base name.
|
1025
|
-
#
|
1026
882
|
# @example
|
1027
883
|
# tag 'app name'
|
1028
884
|
# @example
|
1029
885
|
# tag ''
|
1030
|
-
#
|
1031
886
|
def tag(string)
|
1032
887
|
@options[:tag] = string.to_s
|
1033
888
|
end
|
1034
889
|
|
1035
890
|
# Change the default interval for checking workers.
|
1036
891
|
#
|
1037
|
-
# The default is 5 seconds.
|
892
|
+
# The default value is 5 seconds.
|
1038
893
|
#
|
1039
894
|
# @note Cluster mode only.
|
1040
|
-
#
|
1041
895
|
# @example
|
1042
|
-
# worker_check_interval
|
1043
|
-
#
|
896
|
+
# worker_check_interval 5
|
1044
897
|
# @see Puma::Cluster#check_workers
|
1045
898
|
#
|
1046
899
|
def worker_check_interval(interval)
|
@@ -1053,14 +906,11 @@ module Puma
|
|
1053
906
|
# Setting this value will not protect against slow requests.
|
1054
907
|
#
|
1055
908
|
# This value must be greater than worker_check_interval.
|
1056
|
-
#
|
1057
|
-
# The default is 60 seconds.
|
909
|
+
# The default value is 60 seconds.
|
1058
910
|
#
|
1059
911
|
# @note Cluster mode only.
|
1060
|
-
#
|
1061
912
|
# @example
|
1062
913
|
# worker_timeout 60
|
1063
|
-
#
|
1064
914
|
# @see Puma::Cluster::Worker#ping_timeout
|
1065
915
|
#
|
1066
916
|
def worker_timeout(timeout)
|
@@ -1076,13 +926,12 @@ module Puma
|
|
1076
926
|
|
1077
927
|
# Change the default worker timeout for booting.
|
1078
928
|
#
|
1079
|
-
#
|
929
|
+
# If unspecified, this defaults to the value of worker_timeout.
|
1080
930
|
#
|
1081
931
|
# @note Cluster mode only.
|
1082
932
|
#
|
1083
933
|
# @example
|
1084
934
|
# worker_boot_timeout 60
|
1085
|
-
#
|
1086
935
|
# @see Puma::Cluster::Worker#ping_timeout
|
1087
936
|
#
|
1088
937
|
def worker_boot_timeout(timeout)
|
@@ -1091,13 +940,7 @@ module Puma
|
|
1091
940
|
|
1092
941
|
# Set the timeout for worker shutdown.
|
1093
942
|
#
|
1094
|
-
# The default is 60 seconds.
|
1095
|
-
#
|
1096
943
|
# @note Cluster mode only.
|
1097
|
-
#
|
1098
|
-
# @example
|
1099
|
-
# worker_shutdown_timeout 90
|
1100
|
-
#
|
1101
944
|
# @see Puma::Cluster::Worker#term
|
1102
945
|
#
|
1103
946
|
def worker_shutdown_timeout(timeout)
|
@@ -1113,13 +956,9 @@ module Puma
|
|
1113
956
|
# 2. **:oldest** - the oldest workers (i.e. the workers that were started
|
1114
957
|
# the longest time ago) will be culled.
|
1115
958
|
#
|
1116
|
-
# The default is +:youngest+.
|
1117
|
-
#
|
1118
959
|
# @note Cluster mode only.
|
1119
|
-
#
|
1120
960
|
# @example
|
1121
961
|
# worker_culling_strategy :oldest
|
1122
|
-
#
|
1123
962
|
# @see Puma::Cluster#cull_workers
|
1124
963
|
#
|
1125
964
|
def worker_culling_strategy(strategy)
|
@@ -1132,7 +971,7 @@ module Puma
|
|
1132
971
|
@options[:worker_culling_strategy] = strategy
|
1133
972
|
end
|
1134
973
|
|
1135
|
-
# When set to true, workers accept all requests
|
974
|
+
# When set to true (the default), workers accept all requests
|
1136
975
|
# and queue them before passing them to the handlers.
|
1137
976
|
# When set to false, each worker process accepts exactly as
|
1138
977
|
# many requests as it is configured to simultaneously handle.
|
@@ -1145,11 +984,7 @@ module Puma
|
|
1145
984
|
# slow clients will occupy a handler thread while the request
|
1146
985
|
# is being sent. A reverse proxy, such as nginx, can handle
|
1147
986
|
# slow clients and queue requests before they reach Puma.
|
1148
|
-
#
|
1149
|
-
# The default is +true+.
|
1150
|
-
#
|
1151
987
|
# @see Puma::Server
|
1152
|
-
#
|
1153
988
|
def queue_requests(answer=true)
|
1154
989
|
@options[:queue_requests] = answer
|
1155
990
|
end
|
@@ -1167,13 +1002,9 @@ module Puma
|
|
1167
1002
|
# listening on the socket, allowing workers which are not processing any
|
1168
1003
|
# requests to pick up new requests first.
|
1169
1004
|
#
|
1170
|
-
# The default is 0.005 seconds.
|
1171
|
-
#
|
1172
1005
|
# Only works on MRI. For all other interpreters, this setting does nothing.
|
1173
|
-
#
|
1174
1006
|
# @see Puma::Server#handle_servers
|
1175
1007
|
# @see Puma::ThreadPool#wait_for_less_busy_worker
|
1176
|
-
#
|
1177
1008
|
# @version 5.0.0
|
1178
1009
|
#
|
1179
1010
|
def wait_for_less_busy_worker(val=0.005)
|
@@ -1187,7 +1018,7 @@ module Puma
|
|
1187
1018
|
#
|
1188
1019
|
# There are 5 possible values:
|
1189
1020
|
#
|
1190
|
-
# 1. **:socket** - read the peername from the socket using the
|
1021
|
+
# 1. **:socket** (the default) - read the peername from the socket using the
|
1191
1022
|
# syscall. This is the normal behavior. If this fails for any reason (e.g.,
|
1192
1023
|
# if the peer disconnects between the connection being accepted and the getpeername
|
1193
1024
|
# system call), Puma will return "0.0.0.0"
|
@@ -1205,11 +1036,6 @@ module Puma
|
|
1205
1036
|
# you wish. Because Puma never uses this field anyway, it's format is
|
1206
1037
|
# entirely in your hands.
|
1207
1038
|
#
|
1208
|
-
# The default is +:socket+.
|
1209
|
-
#
|
1210
|
-
# @example
|
1211
|
-
# set_remote_address :localhost
|
1212
|
-
#
|
1213
1039
|
def set_remote_address(val=:socket)
|
1214
1040
|
case val
|
1215
1041
|
when :socket
|
@@ -1250,7 +1076,6 @@ module Puma
|
|
1250
1076
|
# (default 1000), or pass 0 to disable auto refork.
|
1251
1077
|
#
|
1252
1078
|
# @note Cluster mode only.
|
1253
|
-
#
|
1254
1079
|
# @version 5.0.0
|
1255
1080
|
#
|
1256
1081
|
def fork_worker(after_requests=1000)
|
@@ -1260,41 +1085,10 @@ module Puma
|
|
1260
1085
|
# The number of requests to attempt inline before sending a client back to
|
1261
1086
|
# the reactor to be subject to normal ordering.
|
1262
1087
|
#
|
1263
|
-
# The default is 10.
|
1264
|
-
#
|
1265
|
-
# @example
|
1266
|
-
# max_fast_inline 20
|
1267
|
-
#
|
1268
1088
|
def max_fast_inline(num_of_requests)
|
1269
1089
|
@options[:max_fast_inline] = Float(num_of_requests)
|
1270
1090
|
end
|
1271
1091
|
|
1272
|
-
# When `true`, keep-alive connections are maintained on inbound requests.
|
1273
|
-
# Enabling this setting reduces the number of TCP operations, reducing response
|
1274
|
-
# times for connections that can send multiple requests in a single connection.
|
1275
|
-
#
|
1276
|
-
# When Puma receives more incoming connections than available Puma threads,
|
1277
|
-
# enabling the keep-alive behavior may result in processing requests out-of-order,
|
1278
|
-
# increasing overall response time variance. Increased response time variance
|
1279
|
-
# means that the overall average of response times might not change, but more
|
1280
|
-
# outliers will exist. Those long-tail outliers may significantly affect response
|
1281
|
-
# times for some processed requests.
|
1282
|
-
#
|
1283
|
-
# When `false`, Puma closes the connection after each request, requiring the
|
1284
|
-
# client to open a new request. Disabling this setting guarantees that requests
|
1285
|
-
# will be processed in the order they are fully received, decreasing response
|
1286
|
-
# variance and eliminating long-tail outliers caused by keep-alive behavior.
|
1287
|
-
# The trade-off is that the number of TCP operations required will increase.
|
1288
|
-
#
|
1289
|
-
# The default is +true+.
|
1290
|
-
#
|
1291
|
-
# @example
|
1292
|
-
# enable_keep_alives false
|
1293
|
-
#
|
1294
|
-
def enable_keep_alives(enabled=true)
|
1295
|
-
@options[:enable_keep_alives] = enabled
|
1296
|
-
end
|
1297
|
-
|
1298
1092
|
# Specify the backend for the IO selector.
|
1299
1093
|
#
|
1300
1094
|
# Provided values will be passed directly to +NIO::Selector.new+, with the
|
@@ -1314,14 +1108,6 @@ module Puma
|
|
1314
1108
|
@options[:io_selector_backend] = backend.to_sym
|
1315
1109
|
end
|
1316
1110
|
|
1317
|
-
# Ensures +STDOUT+ and +STDERR+ is immediately flushed to the underlying
|
1318
|
-
# operating system and is not buffered internally
|
1319
|
-
#
|
1320
|
-
# The default is +true+.
|
1321
|
-
#
|
1322
|
-
# @example
|
1323
|
-
# mutate_stdout_and_stderr_to_sync_on_write false
|
1324
|
-
#
|
1325
1111
|
def mutate_stdout_and_stderr_to_sync_on_write(enabled=true)
|
1326
1112
|
@options[:mutate_stdout_and_stderr_to_sync_on_write] = enabled
|
1327
1113
|
end
|
@@ -1333,12 +1119,8 @@ module Puma
|
|
1333
1119
|
#
|
1334
1120
|
# When no Content-Length http header is present, it is compared against the
|
1335
1121
|
# size of the body of the request.
|
1336
|
-
|
1337
|
-
# The default is
|
1338
|
-
#
|
1339
|
-
# @example
|
1340
|
-
# http_content_length_limit 2_000_000_000
|
1341
|
-
#
|
1122
|
+
#
|
1123
|
+
# The default value for http_content_length_limit is nil.
|
1342
1124
|
def http_content_length_limit(limit)
|
1343
1125
|
@options[:http_content_length_limit] = limit
|
1344
1126
|
end
|
@@ -1379,7 +1161,6 @@ module Puma
|
|
1379
1161
|
|
1380
1162
|
# To avoid adding cert_pem and key_pem as URI params, we store them on the
|
1381
1163
|
# options[:store] from where Puma binder knows how to find and extract them.
|
1382
|
-
#
|
1383
1164
|
def add_pem_values_to_options_store(opts)
|
1384
1165
|
return if defined?(JRUBY_VERSION)
|
1385
1166
|
|
@@ -1410,9 +1191,7 @@ module Puma
|
|
1410
1191
|
def warn_if_in_single_mode(hook_name)
|
1411
1192
|
return if @options[:silence_fork_callback_warning]
|
1412
1193
|
# user_options (CLI) have precedence over config file
|
1413
|
-
|
1414
|
-
@config.puma_default_options[:workers] || 0
|
1415
|
-
if workers_val == 0
|
1194
|
+
if (@config.options.user_options[:workers] || @options[:workers] || 0) == 0
|
1416
1195
|
log_string =
|
1417
1196
|
"Warning: You specified code to run in a `#{hook_name}` block, " \
|
1418
1197
|
"but Puma is not configured to run in cluster mode (worker count > 0 ), " \
|