puma 3.12.0 → 5.3.1

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.

Files changed (93) hide show
  1. checksums.yaml +4 -4
  2. data/History.md +1413 -439
  3. data/LICENSE +23 -20
  4. data/README.md +131 -60
  5. data/bin/puma-wild +3 -9
  6. data/docs/architecture.md +24 -19
  7. data/docs/compile_options.md +19 -0
  8. data/docs/deployment.md +38 -13
  9. data/docs/fork_worker.md +33 -0
  10. data/docs/jungle/README.md +9 -0
  11. data/{tools → docs}/jungle/rc.d/README.md +1 -1
  12. data/{tools → docs}/jungle/rc.d/puma +2 -2
  13. data/{tools → docs}/jungle/rc.d/puma.conf +0 -0
  14. data/docs/kubernetes.md +66 -0
  15. data/docs/nginx.md +1 -1
  16. data/docs/plugins.md +20 -10
  17. data/docs/rails_dev_mode.md +29 -0
  18. data/docs/restart.md +47 -22
  19. data/docs/signals.md +7 -6
  20. data/docs/stats.md +142 -0
  21. data/docs/systemd.md +48 -70
  22. data/ext/puma_http11/PumaHttp11Service.java +2 -2
  23. data/ext/puma_http11/ext_help.h +1 -1
  24. data/ext/puma_http11/extconf.rb +27 -0
  25. data/ext/puma_http11/http11_parser.c +84 -109
  26. data/ext/puma_http11/http11_parser.h +1 -1
  27. data/ext/puma_http11/http11_parser.java.rl +22 -38
  28. data/ext/puma_http11/http11_parser.rl +4 -2
  29. data/ext/puma_http11/http11_parser_common.rl +3 -3
  30. data/ext/puma_http11/mini_ssl.c +262 -87
  31. data/ext/puma_http11/no_ssl/PumaHttp11Service.java +15 -0
  32. data/ext/puma_http11/org/jruby/puma/Http11.java +108 -116
  33. data/ext/puma_http11/org/jruby/puma/Http11Parser.java +89 -106
  34. data/ext/puma_http11/org/jruby/puma/MiniSSL.java +92 -22
  35. data/ext/puma_http11/puma_http11.c +34 -50
  36. data/lib/puma/app/status.rb +68 -49
  37. data/lib/puma/binder.rb +197 -144
  38. data/lib/puma/cli.rb +17 -15
  39. data/lib/puma/client.rb +257 -226
  40. data/lib/puma/cluster/worker.rb +176 -0
  41. data/lib/puma/cluster/worker_handle.rb +90 -0
  42. data/lib/puma/cluster.rb +223 -212
  43. data/lib/puma/commonlogger.rb +4 -2
  44. data/lib/puma/configuration.rb +58 -51
  45. data/lib/puma/const.rb +41 -19
  46. data/lib/puma/control_cli.rb +117 -73
  47. data/lib/puma/detect.rb +26 -3
  48. data/lib/puma/dsl.rb +531 -123
  49. data/lib/puma/error_logger.rb +104 -0
  50. data/lib/puma/events.rb +57 -31
  51. data/lib/puma/io_buffer.rb +9 -5
  52. data/lib/puma/jruby_restart.rb +2 -58
  53. data/lib/puma/json.rb +96 -0
  54. data/lib/puma/launcher.rb +182 -70
  55. data/lib/puma/minissl/context_builder.rb +79 -0
  56. data/lib/puma/minissl.rb +149 -48
  57. data/lib/puma/null_io.rb +15 -1
  58. data/lib/puma/plugin/tmp_restart.rb +2 -0
  59. data/lib/puma/plugin.rb +8 -12
  60. data/lib/puma/queue_close.rb +26 -0
  61. data/lib/puma/rack/builder.rb +4 -5
  62. data/lib/puma/rack/urlmap.rb +2 -0
  63. data/lib/puma/rack_default.rb +2 -0
  64. data/lib/puma/reactor.rb +87 -316
  65. data/lib/puma/request.rb +456 -0
  66. data/lib/puma/runner.rb +33 -52
  67. data/lib/puma/server.rb +288 -679
  68. data/lib/puma/single.rb +13 -67
  69. data/lib/puma/state_file.rb +10 -3
  70. data/lib/puma/systemd.rb +46 -0
  71. data/lib/puma/thread_pool.rb +131 -81
  72. data/lib/puma/util.rb +14 -6
  73. data/lib/puma.rb +54 -0
  74. data/lib/rack/handler/puma.rb +8 -6
  75. data/tools/Dockerfile +16 -0
  76. data/tools/trickletest.rb +0 -1
  77. metadata +45 -29
  78. data/ext/puma_http11/io_buffer.c +0 -155
  79. data/lib/puma/accept_nonblock.rb +0 -23
  80. data/lib/puma/compat.rb +0 -14
  81. data/lib/puma/convenient.rb +0 -23
  82. data/lib/puma/daemon_ext.rb +0 -31
  83. data/lib/puma/delegation.rb +0 -11
  84. data/lib/puma/java_io_buffer.rb +0 -45
  85. data/lib/puma/rack/backports/uri/common_193.rb +0 -33
  86. data/lib/puma/tcp_logger.rb +0 -39
  87. data/tools/jungle/README.md +0 -19
  88. data/tools/jungle/init.d/README.md +0 -61
  89. data/tools/jungle/init.d/puma +0 -421
  90. data/tools/jungle/init.d/run-puma +0 -18
  91. data/tools/jungle/upstart/README.md +0 -61
  92. data/tools/jungle/upstart/puma-manager.conf +0 -31
  93. data/tools/jungle/upstart/puma.conf +0 -69
data/docs/systemd.md CHANGED
@@ -8,14 +8,12 @@ useful features for running Puma in production.
8
8
  ## Service Configuration
9
9
 
10
10
  Below is a sample puma.service configuration file for systemd, which
11
- can be copied or symlinked to /etc/systemd/system/puma.service, or if
11
+ can be copied or symlinked to `/etc/systemd/system/puma.service`, or if
12
12
  desired, using an application or instance specific name.
13
13
 
14
14
  Note that this uses the systemd preferred "simple" type where the
15
15
  start command remains running in the foreground (does not fork and
16
- exit). See also, the
17
- [Alternative Forking Configuration](#alternative-forking-configuration)
18
- below.
16
+ exit).
19
17
 
20
18
  ~~~~ ini
21
19
  [Unit]
@@ -26,27 +24,39 @@ After=network.target
26
24
  # Requires=puma.socket
27
25
 
28
26
  [Service]
29
- # Foreground process (do not use --daemon in ExecStart or config.rb)
30
- Type=simple
27
+ # Puma supports systemd's `Type=notify` and watchdog service
28
+ # monitoring, if the [sd_notify](https://github.com/agis/ruby-sdnotify) gem is installed,
29
+ # as of Puma 5.1 or later.
30
+ # On earlier versions of Puma or JRuby, change this to `Type=simple` and remove
31
+ # the `WatchdogSec` line.
32
+ Type=notify
33
+
34
+ # If your Puma process locks up, systemd's watchdog will restart it within seconds.
35
+ WatchdogSec=10
31
36
 
32
37
  # Preferably configure a non-privileged user
33
38
  # User=
34
39
 
35
- # The path to the puma application root
36
- # Also replace the "<WD>" place holders below with this path.
37
- WorkingDirectory=
40
+ # The path to the your application code root directory.
41
+ # Also replace the "<YOUR_APP_PATH>" place holders below with this path.
42
+ # Example /home/username/myapp
43
+ WorkingDirectory=<YOUR_APP_PATH>
38
44
 
39
45
  # Helpful for debugging socket activation, etc.
40
46
  # Environment=PUMA_DEBUG=1
41
47
 
42
- # The command to start Puma. This variant uses a binstub generated via
43
- # `bundle binstubs puma --path ./sbin` in the WorkingDirectory
44
- # (replace "<WD>" below)
45
- ExecStart=<WD>/sbin/puma -b tcp://0.0.0.0:9292 -b ssl://0.0.0.0:9293?key=key.pem&cert=cert.pem
48
+ # SystemD will not run puma even if it is in your path. You must specify
49
+ # an absolute URL to puma. For example /usr/local/bin/puma
50
+ # Alternatively, create a binstub with `bundle binstubs puma --path ./sbin` in the WorkingDirectory
51
+ ExecStart=/<FULLPATH>/bin/puma -C <YOUR_APP_PATH>/puma.rb
52
+
53
+ # Variant: Rails start.
54
+ # ExecStart=/<FULLPATH>/bin/puma -C <YOUR_APP_PATH>/config/puma.rb ../config.ru
46
55
 
47
- # Variant: Use config file with `bind` directives instead:
48
- # ExecStart=<WD>/sbin/puma -C config.rb
49
56
  # Variant: Use `bundle exec --keep-file-descriptors puma` instead of binstub
57
+ # Variant: Specify directives inline.
58
+ # ExecStart=/<FULLPATH>/puma -b tcp://0.0.0.0:9292 -b ssl://0.0.0.0:9293?key=key.pem&cert=cert.pem
59
+
50
60
 
51
61
  Restart=always
52
62
 
@@ -66,7 +76,14 @@ listening sockets open across puma restarts and achieves graceful
66
76
  restarts, including when upgraded puma, and is compatible with both
67
77
  clustered mode and application preload.
68
78
 
69
- **Note:** Socket activation doesn't currently work on jruby. This is
79
+ **Note:** Any wrapper scripts which `exec`, or other indirections in
80
+ `ExecStart`, may result in activated socket file descriptors being closed
81
+ before they reach the puma master process. For example, if using `bundle exec`,
82
+ pass the `--keep-file-descriptors` flag. `bundle exec` can be avoided by using a
83
+ `puma` executable generated by `bundle binstubs puma`. This is tracked in
84
+ [#1499].
85
+
86
+ **Note:** Socket activation doesn't currently work on JRuby. This is
70
87
  tracked in [#1367].
71
88
 
72
89
  To use socket activation, configure one or more `ListenStream` sockets
@@ -112,6 +129,21 @@ Puma will detect the release path socket as different than the one provided by
112
129
  systemd and attempt to bind it again, resulting in the exception
113
130
  `There is already a server bound to:`.
114
131
 
132
+ ### Binding
133
+
134
+ By default you need to configure puma to have binds matching with all
135
+ ListenStream statements. Any mismatched systemd ListenStreams will be closed by
136
+ puma.
137
+
138
+ To automatically bind to all activated sockets, the option
139
+ `--bind-to-activated-sockets` can be used. This matches the config DSL
140
+ `bind_to_activated_sockets` statement. This will cause puma to create a bind
141
+ automatically for any activated socket. When systemd socket activation is not
142
+ enabled, this option does nothing.
143
+
144
+ This also accepts an optional argument `only` (DSL: `'only'`) to discard any
145
+ binds that's not socket activated.
146
+
115
147
  ## Usage
116
148
 
117
149
  Without socket activation, use `systemctl` as root (e.g. via `sudo`) as
@@ -197,60 +229,6 @@ Apr 07 08:40:19 hx puma[28320]: * Activated ssl://0.0.0.0:9234?key=key.pem&cert=
197
229
  Apr 07 08:40:19 hx puma[28320]: Use Ctrl-C to stop
198
230
  ~~~~
199
231
 
200
- ## Alternative Forking Configuration
201
-
202
- Other systems/tools might expect or need puma to be run as a
203
- "traditional" forking server, for example so that the `pumactl`
204
- command can be used directly and outside of systemd for
205
- stop/start/restart. This use case is incompatible with systemd socket
206
- activation, so it should not be configured. Below is an alternative
207
- puma.service config sample, using `Type=forking` and the `--daemon`
208
- flag in `ExecStart`. Here systemd is playing a role more equivalent to
209
- SysV init.d, where it is responsible for starting Puma on boot
210
- (multi-user.target) and stopping it on shutdown, but is not performing
211
- continuous restarts. Therefore running Puma in cluster mode, where the
212
- master can restart workers, is highly recommended. See the systemd
213
- [Restart] directive for details.
214
-
215
- ~~~~ ini
216
- [Unit]
217
- Description=Puma HTTP Forking Server
218
- After=network.target
219
-
220
- [Service]
221
- # Background process configuration (use with --daemon in ExecStart)
222
- Type=forking
223
-
224
- # Preferably configure a non-privileged user
225
- # User=
226
-
227
- # The path to the puma application root
228
- # Also replace the "<WD>" place holders below with this path.
229
- WorkingDirectory=
230
-
231
- # The command to start Puma
232
- # (replace "<WD>" below)
233
- ExecStart=bundle exec puma -C <WD>/shared/puma.rb --daemon
234
-
235
- # The command to stop Puma
236
- # (replace "<WD>" below)
237
- ExecStop=bundle exec pumactl -S <WD>/shared/tmp/pids/puma.state stop
238
-
239
- # Path to PID file so that systemd knows which is the master process
240
- PIDFile=<WD>/shared/tmp/pids/puma.pid
241
-
242
- # Should systemd restart puma?
243
- # Use "no" (the default) to ensure no interference when using
244
- # stop/start/restart via `pumactl`. The "on-failure" setting might
245
- # work better for this purpose, but you must test it.
246
- # Use "always" if only `systemctl` is used for start/stop/restart, and
247
- # reconsider if you actually need the forking config.
248
- Restart=no
249
-
250
- [Install]
251
- WantedBy=multi-user.target
252
- ~~~~
253
-
254
232
  ### capistrano3-puma
255
233
 
256
234
  By default,
@@ -1,14 +1,14 @@
1
1
  package puma;
2
2
 
3
3
  import java.io.IOException;
4
-
4
+
5
5
  import org.jruby.Ruby;
6
6
  import org.jruby.runtime.load.BasicLibraryService;
7
7
 
8
8
  import org.jruby.puma.Http11;
9
9
  import org.jruby.puma.MiniSSL;
10
10
 
11
- public class PumaHttp11Service implements BasicLibraryService {
11
+ public class PumaHttp11Service implements BasicLibraryService {
12
12
  public boolean basicLoad(final Ruby runtime) throws IOException {
13
13
  Http11.createHttp11(runtime);
14
14
  MiniSSL.createMiniSSL(runtime);
@@ -2,7 +2,7 @@
2
2
  #define ext_help_h
3
3
 
4
4
  #define RAISE_NOT_NULL(T) if(T == NULL) rb_raise(rb_eArgError, "%s", "NULL found for " # T " when shouldn't be.");
5
- #define DATA_GET(from,type,name) Data_Get_Struct(from,type,name); RAISE_NOT_NULL(name);
5
+ #define DATA_GET(from,type,data_type,name) TypedData_Get_Struct(from,type,data_type,name); RAISE_NOT_NULL(name);
6
6
  #define REQUIRE_TYPE(V, T) if(TYPE(V) != T) rb_raise(rb_eTypeError, "%s", "Wrong argument type for " # V " required " # T);
7
7
  #define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
8
8
 
@@ -2,6 +2,12 @@ require 'mkmf'
2
2
 
3
3
  dir_config("puma_http11")
4
4
 
5
+ if $mingw && RUBY_VERSION >= '2.4'
6
+ append_cflags '-fstack-protector-strong -D_FORTIFY_SOURCE=2'
7
+ append_ldflags '-fstack-protector-strong -l:libssp.a'
8
+ have_library 'ssp'
9
+ end
10
+
5
11
  unless ENV["DISABLE_SSL"]
6
12
  dir_config("openssl")
7
13
 
@@ -9,6 +15,27 @@ unless ENV["DISABLE_SSL"]
9
15
  %w'ssl ssleay32'.find {|ssl| have_library(ssl, 'SSL_CTX_new')}
10
16
 
11
17
  have_header "openssl/bio.h"
18
+
19
+ # below is yes for 1.0.2 & later
20
+ have_func "DTLS_method" , "openssl/ssl.h"
21
+
22
+ # below are yes for 1.1.0 & later
23
+ have_func "TLS_server_method" , "openssl/ssl.h"
24
+ have_func "SSL_CTX_set_min_proto_version(NULL, 0)", "openssl/ssl.h"
25
+
26
+ have_func "X509_STORE_up_ref"
27
+ have_func("SSL_CTX_set_ecdh_auto(NULL, 0)", "openssl/ssl.h")
28
+ end
29
+ end
30
+
31
+ if ENV["MAKE_WARNINGS_INTO_ERRORS"]
32
+ # Make all warnings into errors
33
+ # Except `implicit-fallthrough` since most failures comes from ragel state machine generated code
34
+ if respond_to? :append_cflags
35
+ append_cflags config_string 'WERRORFLAG'
36
+ append_cflags '-Wno-implicit-fallthrough'
37
+ else
38
+ $CFLAGS += ' ' << (config_string 'WERRORFLAG') << ' -Wno-implicit-fallthrough'
12
39
  end
13
40
  end
14
41