puma 3.11.1 → 6.6.0

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.
Files changed (98) hide show
  1. checksums.yaml +5 -5
  2. data/History.md +2092 -422
  3. data/LICENSE +23 -20
  4. data/README.md +301 -69
  5. data/bin/puma-wild +3 -9
  6. data/docs/architecture.md +59 -21
  7. data/docs/compile_options.md +55 -0
  8. data/docs/deployment.md +69 -58
  9. data/docs/fork_worker.md +41 -0
  10. data/docs/java_options.md +54 -0
  11. data/docs/jungle/README.md +9 -0
  12. data/docs/jungle/rc.d/README.md +74 -0
  13. data/docs/jungle/rc.d/puma +61 -0
  14. data/docs/jungle/rc.d/puma.conf +10 -0
  15. data/docs/kubernetes.md +78 -0
  16. data/docs/nginx.md +2 -2
  17. data/docs/plugins.md +26 -12
  18. data/docs/rails_dev_mode.md +28 -0
  19. data/docs/restart.md +48 -22
  20. data/docs/signals.md +13 -11
  21. data/docs/stats.md +147 -0
  22. data/docs/systemd.md +108 -117
  23. data/docs/testing_benchmarks_local_files.md +150 -0
  24. data/docs/testing_test_rackup_ci_files.md +36 -0
  25. data/ext/puma_http11/PumaHttp11Service.java +2 -2
  26. data/ext/puma_http11/ext_help.h +1 -1
  27. data/ext/puma_http11/extconf.rb +68 -3
  28. data/ext/puma_http11/http11_parser.c +106 -118
  29. data/ext/puma_http11/http11_parser.h +2 -2
  30. data/ext/puma_http11/http11_parser.java.rl +22 -38
  31. data/ext/puma_http11/http11_parser.rl +6 -4
  32. data/ext/puma_http11/http11_parser_common.rl +6 -6
  33. data/ext/puma_http11/mini_ssl.c +474 -94
  34. data/ext/puma_http11/no_ssl/PumaHttp11Service.java +15 -0
  35. data/ext/puma_http11/org/jruby/puma/Http11.java +136 -121
  36. data/ext/puma_http11/org/jruby/puma/Http11Parser.java +84 -99
  37. data/ext/puma_http11/org/jruby/puma/MiniSSL.java +251 -88
  38. data/ext/puma_http11/puma_http11.c +53 -58
  39. data/lib/puma/app/status.rb +71 -49
  40. data/lib/puma/binder.rb +257 -151
  41. data/lib/puma/cli.rb +61 -38
  42. data/lib/puma/client.rb +464 -224
  43. data/lib/puma/cluster/worker.rb +183 -0
  44. data/lib/puma/cluster/worker_handle.rb +96 -0
  45. data/lib/puma/cluster.rb +343 -239
  46. data/lib/puma/commonlogger.rb +23 -14
  47. data/lib/puma/configuration.rb +144 -96
  48. data/lib/puma/const.rb +194 -115
  49. data/lib/puma/control_cli.rb +135 -81
  50. data/lib/puma/detect.rb +34 -2
  51. data/lib/puma/dsl.rb +1092 -153
  52. data/lib/puma/error_logger.rb +113 -0
  53. data/lib/puma/events.rb +17 -111
  54. data/lib/puma/io_buffer.rb +44 -5
  55. data/lib/puma/jruby_restart.rb +2 -73
  56. data/lib/puma/json_serialization.rb +96 -0
  57. data/lib/puma/launcher/bundle_pruner.rb +104 -0
  58. data/lib/puma/launcher.rb +205 -138
  59. data/lib/puma/log_writer.rb +147 -0
  60. data/lib/puma/minissl/context_builder.rb +96 -0
  61. data/lib/puma/minissl.rb +279 -70
  62. data/lib/puma/null_io.rb +61 -2
  63. data/lib/puma/plugin/systemd.rb +90 -0
  64. data/lib/puma/plugin/tmp_restart.rb +3 -1
  65. data/lib/puma/plugin.rb +9 -13
  66. data/lib/puma/rack/builder.rb +10 -11
  67. data/lib/puma/rack/urlmap.rb +3 -1
  68. data/lib/puma/rack_default.rb +21 -4
  69. data/lib/puma/reactor.rb +97 -185
  70. data/lib/puma/request.rb +688 -0
  71. data/lib/puma/runner.rb +114 -69
  72. data/lib/puma/sd_notify.rb +146 -0
  73. data/lib/puma/server.rb +409 -704
  74. data/lib/puma/single.rb +29 -72
  75. data/lib/puma/state_file.rb +48 -9
  76. data/lib/puma/thread_pool.rb +234 -93
  77. data/lib/puma/util.rb +23 -10
  78. data/lib/puma.rb +68 -5
  79. data/lib/rack/handler/puma.rb +119 -86
  80. data/tools/Dockerfile +16 -0
  81. data/tools/trickletest.rb +0 -1
  82. metadata +55 -33
  83. data/ext/puma_http11/io_buffer.c +0 -155
  84. data/lib/puma/accept_nonblock.rb +0 -23
  85. data/lib/puma/compat.rb +0 -14
  86. data/lib/puma/convenient.rb +0 -23
  87. data/lib/puma/daemon_ext.rb +0 -31
  88. data/lib/puma/delegation.rb +0 -11
  89. data/lib/puma/java_io_buffer.rb +0 -45
  90. data/lib/puma/rack/backports/uri/common_193.rb +0 -33
  91. data/lib/puma/tcp_logger.rb +0 -39
  92. data/tools/jungle/README.md +0 -13
  93. data/tools/jungle/init.d/README.md +0 -59
  94. data/tools/jungle/init.d/puma +0 -421
  95. data/tools/jungle/init.d/run-puma +0 -18
  96. data/tools/jungle/upstart/README.md +0 -61
  97. data/tools/jungle/upstart/puma-manager.conf +0 -31
  98. data/tools/jungle/upstart/puma.conf +0 -69
data/lib/puma/cli.rb CHANGED
@@ -1,35 +1,33 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'optparse'
2
4
  require 'uri'
3
5
 
4
- require 'puma/configuration'
5
- require 'puma/launcher'
6
- require 'puma/const'
7
- require 'puma/events'
6
+ require_relative '../puma'
7
+ require_relative 'configuration'
8
+ require_relative 'launcher'
9
+ require_relative 'const'
10
+ require_relative 'log_writer'
8
11
 
9
12
  module Puma
10
13
  class << self
11
- # The CLI exports its Puma::Configuration object here to allow
12
- # apps to pick it up. An app needs to use it conditionally though
13
- # since it is not set if the app is launched via another
14
- # mechanism than the CLI class.
14
+ # The CLI exports a Puma::Configuration instance here to allow
15
+ # apps to pick it up. An app must load this object conditionally
16
+ # because it is not set if the app is launched via any mechanism
17
+ # other than the CLI class.
15
18
  attr_accessor :cli_config
16
19
  end
17
20
 
18
21
  # Handles invoke a Puma::Server in a command line style.
19
22
  #
20
23
  class CLI
21
- KEYS_NOT_TO_PERSIST_IN_STATE = Launcher::KEYS_NOT_TO_PERSIST_IN_STATE
22
-
23
24
  # Create a new CLI object using +argv+ as the command line
24
25
  # arguments.
25
26
  #
26
- # +stdout+ and +stderr+ can be set to IO-like objects which
27
- # this object will report status on.
28
- #
29
- def initialize(argv, events=Events.stdio)
27
+ def initialize(argv, log_writer = LogWriter.stdio, events = Events.new, env: ENV)
30
28
  @debug = false
31
29
  @argv = argv.dup
32
-
30
+ @log_writer = log_writer
33
31
  @events = events
34
32
 
35
33
  @conf = nil
@@ -41,7 +39,7 @@ module Puma
41
39
  @control_url = nil
42
40
  @control_options = {}
43
41
 
44
- setup_options
42
+ setup_options env
45
43
 
46
44
  begin
47
45
  @parser.parse! @argv
@@ -65,7 +63,7 @@ module Puma
65
63
  end
66
64
  end
67
65
 
68
- @launcher = Puma::Launcher.new(@conf, :events => @events, :argv => argv)
66
+ @launcher = Puma::Launcher.new(@conf, env: ENV, log_writer: @log_writer, events: @events, argv: argv)
69
67
  end
70
68
 
71
69
  attr_reader :launcher
@@ -77,33 +75,45 @@ module Puma
77
75
  @launcher.run
78
76
  end
79
77
 
80
- private
78
+ private
81
79
  def unsupported(str)
82
- @events.error(str)
80
+ @log_writer.error(str)
83
81
  raise UnsupportedOption
84
82
  end
85
83
 
84
+ def configure_control_url(command_line_arg)
85
+ if command_line_arg
86
+ @control_url = command_line_arg
87
+ elsif Puma.jruby?
88
+ unsupported "No default url available on JRuby"
89
+ end
90
+ end
91
+
86
92
  # Build the OptionParser object to handle the available options.
87
93
  #
88
94
 
89
- def setup_options
90
- @conf = Configuration.new do |user_config, file_config|
95
+ def setup_options(env = ENV)
96
+ @conf = Configuration.new({}, {events: @events}, env) do |user_config, file_config|
91
97
  @parser = OptionParser.new do |o|
92
98
  o.on "-b", "--bind URI", "URI to bind to (tcp://, unix://, ssl://)" do |arg|
93
99
  user_config.bind arg
94
100
  end
95
101
 
102
+ o.on "--bind-to-activated-sockets [only]", "Bind to all activated sockets" do |arg|
103
+ user_config.bind_to_activated_sockets(arg || true)
104
+ end
105
+
96
106
  o.on "-C", "--config PATH", "Load PATH as a config file" do |arg|
97
107
  file_config.load arg
98
108
  end
99
109
 
100
- o.on "--control URL", "The bind url to use for the control server",
101
- "Use 'auto' to use temp unix server" do |arg|
102
- if arg
103
- @control_url = arg
104
- elsif Puma.jruby?
105
- unsupported "No default url available on JRuby"
106
- end
110
+ # Identical to supplying --config "-", but more semantic
111
+ o.on "--no-config", "Prevent Puma from searching for a config file" do |arg|
112
+ file_config.load "-"
113
+ end
114
+
115
+ o.on "--control-url URL", "The bind url to use for the control server. Use 'auto' to use temp unix server" do |arg|
116
+ configure_control_url(arg)
107
117
  end
108
118
 
109
119
  o.on "--control-token TOKEN",
@@ -111,11 +121,6 @@ module Puma
111
121
  @control_options[:auth_token] = arg
112
122
  end
113
123
 
114
- o.on "-d", "--daemon", "Daemonize the server into the background" do
115
- user_config.daemonize
116
- user_config.quiet
117
- end
118
-
119
124
  o.on "--debug", "Log lowlevel debugging information" do
120
125
  user_config.debug
121
126
  end
@@ -129,19 +134,33 @@ module Puma
129
134
  user_config.environment arg
130
135
  end
131
136
 
137
+ o.on "-f", "--fork-worker=[REQUESTS]", OptionParser::DecimalInteger,
138
+ "Fork new workers from existing worker. Cluster mode only",
139
+ "Auto-refork after REQUESTS (default 1000)" do |*args|
140
+ user_config.fork_worker(*args.compact)
141
+ end
142
+
132
143
  o.on "-I", "--include PATH", "Specify $LOAD_PATH directories" do |arg|
133
144
  $LOAD_PATH.unshift(*arg.split(':'))
134
145
  end
135
146
 
147
+ o.on "--idle-timeout SECONDS", "Number of seconds until the next request before automatic shutdown" do |arg|
148
+ user_config.idle_timeout arg
149
+ end
150
+
136
151
  o.on "-p", "--port PORT", "Define the TCP port to bind to",
137
152
  "Use -b for more advanced options" do |arg|
138
- user_config.bind "tcp://#{Configuration::DefaultTCPHost}:#{arg}"
153
+ user_config.bind "tcp://#{Configuration::DEFAULTS[:tcp_host]}:#{arg}"
139
154
  end
140
155
 
141
156
  o.on "--pidfile PATH", "Use PATH as a pidfile" do |arg|
142
157
  user_config.pidfile arg
143
158
  end
144
159
 
160
+ o.on "--plugin PLUGIN", "Load the given PLUGIN. Can be used multiple times to load multiple plugins." do |arg|
161
+ user_config.plugin arg
162
+ end
163
+
145
164
  o.on "--preload", "Preload the app. Cluster mode only" do
146
165
  user_config.preload_app!
147
166
  end
@@ -150,6 +169,10 @@ module Puma
150
169
  user_config.prune_bundler
151
170
  end
152
171
 
172
+ o.on "--extra-runtime-dependencies GEM1,GEM2", "Defines any extra needed gems when using --prune-bundler" do |arg|
173
+ user_config.extra_runtime_dependencies arg.split(',')
174
+ end
175
+
153
176
  o.on "-q", "--quiet", "Do not log requests internally (default true)" do
154
177
  user_config.quiet
155
178
  end
@@ -164,6 +187,10 @@ module Puma
164
187
  user_config.restart_command cmd
165
188
  end
166
189
 
190
+ o.on "-s", "--silent", "Do not log prompt messages other than errors" do
191
+ @log_writer = LogWriter.new(NullIO.new, $stderr)
192
+ end
193
+
167
194
  o.on "-S", "--state PATH", "Where to store the state details" do |arg|
168
195
  user_config.state_path arg
169
196
  end
@@ -177,10 +204,6 @@ module Puma
177
204
  end
178
205
  end
179
206
 
180
- o.on "--tcp-mode", "Run the app in raw TCP mode instead of HTTP mode" do
181
- user_config.tcp_mode!
182
- end
183
-
184
207
  o.on "--early-hints", "Enable early hints support" do
185
208
  user_config.early_hints
186
209
  end