puma 3.8.2 → 3.12.6

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 (67) hide show
  1. checksums.yaml +5 -5
  2. data/History.md +153 -0
  3. data/README.md +140 -230
  4. data/docs/architecture.md +36 -0
  5. data/docs/images/puma-connection-flow-no-reactor.png +0 -0
  6. data/docs/images/puma-connection-flow.png +0 -0
  7. data/docs/images/puma-general-arch.png +0 -0
  8. data/docs/plugins.md +28 -0
  9. data/docs/restart.md +39 -0
  10. data/docs/signals.md +56 -3
  11. data/docs/systemd.md +112 -37
  12. data/ext/puma_http11/http11_parser.c +87 -85
  13. data/ext/puma_http11/http11_parser.rl +12 -10
  14. data/ext/puma_http11/mini_ssl.c +31 -5
  15. data/ext/puma_http11/org/jruby/puma/Http11Parser.java +13 -16
  16. data/ext/puma_http11/org/jruby/puma/MiniSSL.java +15 -2
  17. data/lib/puma/app/status.rb +8 -0
  18. data/lib/puma/binder.rb +22 -17
  19. data/lib/puma/cli.rb +22 -7
  20. data/lib/puma/client.rb +41 -2
  21. data/lib/puma/cluster.rb +28 -7
  22. data/lib/puma/commonlogger.rb +2 -0
  23. data/lib/puma/configuration.rb +21 -14
  24. data/lib/puma/const.rb +17 -2
  25. data/lib/puma/control_cli.rb +16 -14
  26. data/lib/puma/convenient.rb +2 -0
  27. data/lib/puma/daemon_ext.rb +2 -0
  28. data/lib/puma/delegation.rb +2 -0
  29. data/lib/puma/detect.rb +2 -0
  30. data/lib/puma/dsl.rb +46 -9
  31. data/lib/puma/events.rb +3 -2
  32. data/lib/puma/io_buffer.rb +2 -0
  33. data/lib/puma/java_io_buffer.rb +2 -0
  34. data/lib/puma/jruby_restart.rb +2 -1
  35. data/lib/puma/launcher.rb +42 -20
  36. data/lib/puma/minissl.rb +67 -28
  37. data/lib/puma/null_io.rb +2 -0
  38. data/lib/puma/plugin/tmp_restart.rb +0 -1
  39. data/lib/puma/plugin.rb +2 -0
  40. data/lib/puma/rack/builder.rb +2 -1
  41. data/lib/puma/reactor.rb +137 -0
  42. data/lib/puma/runner.rb +16 -3
  43. data/lib/puma/server.rb +145 -29
  44. data/lib/puma/single.rb +14 -3
  45. data/lib/puma/state_file.rb +2 -0
  46. data/lib/puma/tcp_logger.rb +2 -0
  47. data/lib/puma/thread_pool.rb +55 -6
  48. data/lib/puma/util.rb +1 -0
  49. data/lib/puma.rb +8 -0
  50. data/lib/rack/handler/puma.rb +13 -2
  51. data/tools/jungle/README.md +12 -2
  52. data/tools/jungle/init.d/README.md +2 -0
  53. data/tools/jungle/init.d/puma +2 -2
  54. data/tools/jungle/init.d/run-puma +1 -1
  55. data/tools/jungle/rc.d/README.md +74 -0
  56. data/tools/jungle/rc.d/puma +61 -0
  57. data/tools/jungle/rc.d/puma.conf +10 -0
  58. data/tools/trickletest.rb +1 -1
  59. metadata +21 -95
  60. data/.github/issue_template.md +0 -20
  61. data/Gemfile +0 -12
  62. data/Manifest.txt +0 -78
  63. data/Rakefile +0 -158
  64. data/Release.md +0 -9
  65. data/gemfiles/2.1-Gemfile +0 -12
  66. data/puma.gemspec +0 -52
  67. /data/{DEPLOYMENT.md → docs/deployment.md} +0 -0
data/docs/signals.md CHANGED
@@ -36,8 +36,61 @@ Puma cluster responds to these signals:
36
36
  - `TTIN` increment the worker count by 1
37
37
  - `TTOU` decrement the worker count by 1
38
38
  - `TERM` send `TERM` to worker. Worker will attempt to finish then exit.
39
- - `USR2` restart workers
40
- - `USR1` restart workers in phases, a rolling restart.
41
- - `HUP` reopen log files defined in stdout_redirect configuration parameter
39
+ - `USR2` restart workers. This also reloads puma configuration file, if there is one.
40
+ - `USR1` restart workers in phases, a rolling restart. This will not reload configuration file.
41
+ - `HUP` reopen log files defined in stdout_redirect configuration parameter. If there is no stdout_redirect option provided it will behave like `INT`
42
42
  - `INT` equivalent of sending Ctrl-C to cluster. Will attempt to finish then exit.
43
43
  - `CHLD`
44
+
45
+ ## Callbacks order in case of different signals
46
+
47
+ ### Start application
48
+
49
+ ```
50
+ puma configuration file reloaded, if there is one
51
+ * Pruning Bundler environment
52
+ puma configuration file reloaded, if there is one
53
+
54
+ before_fork
55
+ on_worker_fork
56
+ after_worker_fork
57
+
58
+ Gemfile in context
59
+
60
+ on_worker_boot
61
+
62
+ Code of the app is loaded and running
63
+ ```
64
+
65
+ ### Send USR2
66
+
67
+ ```
68
+ on_worker_shutdown
69
+ on_restart
70
+
71
+ puma configuration file reloaded, if there is one
72
+
73
+ before_fork
74
+ on_worker_fork
75
+ after_worker_fork
76
+
77
+ Gemfile in context
78
+
79
+ on_worker_boot
80
+
81
+ Code of the app is loaded and running
82
+ ```
83
+
84
+ ### Send USR1
85
+
86
+ ```
87
+ on_worker_shutdown
88
+ on_worker_fork
89
+ after_worker_fork
90
+
91
+ Gemfile in context
92
+
93
+ on_worker_boot
94
+
95
+ Code of the app is loaded and running
96
+ ```
data/docs/systemd.md CHANGED
@@ -3,10 +3,21 @@
3
3
  [systemd](https://www.freedesktop.org/wiki/Software/systemd/) is a
4
4
  commonly available init system (PID 1) on many Linux distributions. It
5
5
  offers process monitoring (including automatic restarts) and other
6
- useful features for running Puma in production. Below is a sample
7
- puma.service configuration file for systemd:
6
+ useful features for running Puma in production.
8
7
 
9
- ~~~~
8
+ ## Service Configuration
9
+
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
12
+ desired, using an application or instance specific name.
13
+
14
+ Note that this uses the systemd preferred "simple" type where the
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.
19
+
20
+ ~~~~ ini
10
21
  [Unit]
11
22
  Description=Puma HTTP Server
12
23
  After=network.target
@@ -21,22 +32,21 @@ Type=simple
21
32
  # Preferably configure a non-privileged user
22
33
  # User=
23
34
 
24
- # Specify the path to your puma application root
25
- # WorkingDirectory=
35
+ # The path to the puma application root
36
+ # Also replace the "<WD>" place holders below with this path.
37
+ WorkingDirectory=
26
38
 
27
39
  # Helpful for debugging socket activation, etc.
28
40
  # Environment=PUMA_DEBUG=1
29
41
 
30
- # The command to start Puma
31
- # Here we are using a binstub generated via:
32
- # `bundle binstubs puma --path ./sbin`
33
- # in the WorkingDirectory (replace <WD> below)
34
- # You can alternatively use `bundle exec --keep-file-descriptors puma`
35
- # ExecStart=<WD>/sbin/puma -b tcp://0.0.0.0:9292 -b ssl://0.0.0.0:9293?key=key.pem&cert=cert.pem
36
-
37
- # Alternatively with a config file (in WorkingDirectory) and
38
- # comparable `bind` directives
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
46
+
47
+ # Variant: Use config file with `bind` directives instead:
39
48
  # ExecStart=<WD>/sbin/puma -C config.rb
49
+ # Variant: Use `bundle exec --keep-file-descriptors puma` instead of binstub
40
50
 
41
51
  Restart=always
42
52
 
@@ -50,14 +60,22 @@ for additional details.
50
60
  ## Socket Activation
51
61
 
52
62
  systemd and puma also support socket activation, where systemd opens
53
- the listening socket(s) in advance and provides them to the puma master
54
- process on startup. Among other advantages, this keeps listening
55
- sockets open across puma restarts and achieves graceful restarts. To
56
- use socket activation, configure one or more `ListenStream`
57
- sockets in a companion `*.socket` systemd config file. Here is a sample
58
- puma.socket, matching the ports used in the above puma.service:
59
-
60
- ~~~~
63
+ the listening socket(s) in advance and provides them to the puma
64
+ master process on startup. Among other advantages, this keeps
65
+ listening sockets open across puma restarts and achieves graceful
66
+ restarts, including when upgraded puma, and is compatible with both
67
+ clustered mode and application preload.
68
+
69
+ **Note:** Socket activation doesn't currently work on jruby. This is
70
+ tracked in [#1367].
71
+
72
+ To use socket activation, configure one or more `ListenStream` sockets
73
+ in a companion `*.socket` unit file. Also uncomment the associated
74
+ `Requires` directive for the socket unit in the service file (see
75
+ above.) Here is a sample puma.socket, matching the ports used in the
76
+ above puma.service:
77
+
78
+ ~~~~ ini
61
79
  [Unit]
62
80
  Description=Puma HTTP Server Accept Sockets
63
81
 
@@ -84,6 +102,16 @@ for additional configuration details.
84
102
  Note that the above configurations will work with Puma in either
85
103
  single process or cluster mode.
86
104
 
105
+ ### Sockets and symlinks
106
+
107
+ When using releases folders, you should set the socket path using the
108
+ shared folder path (ex. `/srv/projet/shared/tmp/puma.sock`), not the
109
+ release folder path (`/srv/projet/releases/1234/tmp/puma.sock`).
110
+
111
+ Puma will detect the release path socket as different than the one provided by
112
+ systemd and attempt to bind it again, resulting in the exception
113
+ `There is already a server bound to:`.
114
+
87
115
  ## Usage
88
116
 
89
117
  Without socket activation, use `systemctl` as root (e.g. via `sudo`) as
@@ -169,29 +197,76 @@ Apr 07 08:40:19 hx puma[28320]: * Activated ssl://0.0.0.0:9234?key=key.pem&cert=
169
197
  Apr 07 08:40:19 hx puma[28320]: Use Ctrl-C to stop
170
198
  ~~~~
171
199
 
172
- ## Alternative background process configuration
173
-
174
- If Capistrano and [capistrano3-puma](https://github.com/seuros/capistrano-puma) tasks are used you can use the following configuration. In this case, you would skip systemd Socket Activation, since Puma handles the socket by itself:
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
175
219
 
176
- ~~~~
177
220
  [Service]
178
221
  # Background process configuration (use with --daemon in ExecStart)
179
222
  Type=forking
180
223
 
181
- # To learn which exact command is to be used to execute at "ExecStart" of this
182
- # Service, ask Capistrano: `cap <stage> puma:start --dry-run`. Your result
183
- # may differ from this example, for example if you use a Ruby version
184
- # manager. `<WD>` is short for "your working directory". Replace it with your
185
- # path.
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)
186
233
  ExecStart=bundle exec puma -C <WD>/shared/puma.rb --daemon
187
234
 
188
- # To learn which exact command is to be used to execute at "ExecStop" of this
189
- # Service, ask Capistrano: `cap <stage> puma:stop --dry-run`. Your result
190
- # may differ from this example, for example if you use a Ruby version
191
- # manager. `<WD>` is short for "your working directory". Replace it with your
192
- # path.
235
+ # The command to stop Puma
236
+ # (replace "<WD>" below)
193
237
  ExecStop=bundle exec pumactl -S <WD>/shared/tmp/pids/puma.state stop
194
238
 
195
- # PIDFile setting is required in order to work properly
239
+ # Path to PID file so that systemd knows which is the master process
196
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
197
252
  ~~~~
253
+
254
+ ### capistrano3-puma
255
+
256
+ By default,
257
+ [capistrano3-puma](https://github.com/seuros/capistrano-puma) uses
258
+ `pumactl` for deployment restarts, outside of systemd. To learn the
259
+ exact commands that this tool would use for `ExecStart` and
260
+ `ExecStop`, use the following `cap` commands in dry-run mode, and
261
+ update from the above forking service configuration accordingly. Note
262
+ also that the configured `User` should likely be the same as the
263
+ capistrano3-puma `:puma_user` option.
264
+
265
+ ~~~~ sh
266
+ stage=production # or different stage, as needed
267
+ cap $stage puma:start --dry-run
268
+ cap $stage puma:stop --dry-run
269
+ ~~~~
270
+
271
+ [Restart]: https://www.freedesktop.org/software/systemd/man/systemd.service.html#Restart=
272
+ [#1367]: https://github.com/puma/puma/issues/1367