puma 2.16.0 → 3.11.4

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 (78) hide show
  1. checksums.yaml +5 -5
  2. data/{History.txt → History.md} +489 -70
  3. data/README.md +143 -174
  4. data/docs/architecture.md +36 -0
  5. data/{DEPLOYMENT.md → docs/deployment.md} +1 -1
  6. data/docs/images/puma-connection-flow-no-reactor.png +0 -0
  7. data/docs/images/puma-connection-flow.png +0 -0
  8. data/docs/images/puma-general-arch.png +0 -0
  9. data/docs/nginx.md +2 -2
  10. data/docs/plugins.md +28 -0
  11. data/docs/restart.md +39 -0
  12. data/docs/signals.md +56 -3
  13. data/docs/systemd.md +272 -0
  14. data/ext/puma_http11/extconf.rb +2 -0
  15. data/ext/puma_http11/http11_parser.c +291 -447
  16. data/ext/puma_http11/http11_parser.h +1 -0
  17. data/ext/puma_http11/http11_parser.java.rl +5 -5
  18. data/ext/puma_http11/http11_parser.rl +10 -9
  19. data/ext/puma_http11/http11_parser_common.rl +1 -1
  20. data/ext/puma_http11/io_buffer.c +8 -8
  21. data/ext/puma_http11/mini_ssl.c +64 -6
  22. data/ext/puma_http11/org/jruby/puma/Http11Parser.java +113 -131
  23. data/ext/puma_http11/org/jruby/puma/MiniSSL.java +9 -2
  24. data/ext/puma_http11/puma_http11.c +1 -0
  25. data/lib/puma/app/status.rb +9 -1
  26. data/lib/puma/binder.rb +90 -38
  27. data/lib/puma/cli.rb +134 -491
  28. data/lib/puma/client.rb +142 -4
  29. data/lib/puma/cluster.rb +132 -76
  30. data/lib/puma/commonlogger.rb +19 -20
  31. data/lib/puma/compat.rb +3 -7
  32. data/lib/puma/configuration.rb +206 -67
  33. data/lib/puma/const.rb +21 -31
  34. data/lib/puma/control_cli.rb +92 -103
  35. data/lib/puma/convenient.rb +23 -0
  36. data/lib/puma/daemon_ext.rb +6 -0
  37. data/lib/puma/detect.rb +10 -1
  38. data/lib/puma/dsl.rb +203 -45
  39. data/lib/puma/events.rb +22 -13
  40. data/lib/puma/io_buffer.rb +1 -1
  41. data/lib/puma/jruby_restart.rb +1 -2
  42. data/lib/puma/launcher.rb +431 -0
  43. data/lib/puma/minissl.rb +83 -4
  44. data/lib/puma/null_io.rb +19 -11
  45. data/lib/puma/plugin/tmp_restart.rb +34 -0
  46. data/lib/puma/plugin.rb +115 -0
  47. data/lib/puma/rack/backports/uri/common_193.rb +17 -13
  48. data/lib/puma/rack/builder.rb +3 -0
  49. data/lib/puma/rack/urlmap.rb +9 -8
  50. data/lib/puma/reactor.rb +18 -0
  51. data/lib/puma/runner.rb +43 -15
  52. data/lib/puma/server.rb +141 -35
  53. data/lib/puma/single.rb +16 -6
  54. data/lib/puma/state_file.rb +29 -0
  55. data/lib/puma/tcp_logger.rb +8 -1
  56. data/lib/puma/thread_pool.rb +60 -10
  57. data/lib/puma/util.rb +1 -5
  58. data/lib/puma.rb +13 -4
  59. data/lib/rack/handler/puma.rb +76 -29
  60. data/tools/jungle/README.md +12 -2
  61. data/tools/jungle/init.d/README.md +9 -2
  62. data/tools/jungle/init.d/puma +86 -59
  63. data/tools/jungle/init.d/run-puma +16 -1
  64. data/tools/jungle/rc.d/README.md +74 -0
  65. data/tools/jungle/rc.d/puma +61 -0
  66. data/tools/jungle/rc.d/puma.conf +10 -0
  67. data/tools/jungle/upstart/puma.conf +1 -1
  68. data/tools/trickletest.rb +1 -1
  69. metadata +28 -95
  70. data/COPYING +0 -55
  71. data/Gemfile +0 -13
  72. data/Manifest.txt +0 -74
  73. data/Rakefile +0 -158
  74. data/docs/config.md +0 -0
  75. data/lib/puma/capistrano.rb +0 -94
  76. data/lib/puma/rack/backports/uri/common_18.rb +0 -56
  77. data/lib/puma/rack/backports/uri/common_192.rb +0 -52
  78. data/puma.gemspec +0 -52
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 ADDED
@@ -0,0 +1,272 @@
1
+ # systemd
2
+
3
+ [systemd](https://www.freedesktop.org/wiki/Software/systemd/) is a
4
+ commonly available init system (PID 1) on many Linux distributions. It
5
+ offers process monitoring (including automatic restarts) and other
6
+ useful features for running Puma in production.
7
+
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
21
+ [Unit]
22
+ Description=Puma HTTP Server
23
+ After=network.target
24
+
25
+ # Uncomment for socket activation (see below)
26
+ # Requires=puma.socket
27
+
28
+ [Service]
29
+ # Foreground process (do not use --daemon in ExecStart or config.rb)
30
+ Type=simple
31
+
32
+ # Preferably configure a non-privileged user
33
+ # User=
34
+
35
+ # The path to the puma application root
36
+ # Also replace the "<WD>" place holders below with this path.
37
+ WorkingDirectory=
38
+
39
+ # Helpful for debugging socket activation, etc.
40
+ # Environment=PUMA_DEBUG=1
41
+
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:
48
+ # ExecStart=<WD>/sbin/puma -C config.rb
49
+ # Variant: Use `bundle exec --keep-file-descriptors puma` instead of binstub
50
+
51
+ Restart=always
52
+
53
+ [Install]
54
+ WantedBy=multi-user.target
55
+ ~~~~
56
+
57
+ See [systemd.exec](https://www.freedesktop.org/software/systemd/man/systemd.exec.html)
58
+ for additional details.
59
+
60
+ ## Socket Activation
61
+
62
+ systemd and puma also support socket activation, where systemd opens
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
79
+ [Unit]
80
+ Description=Puma HTTP Server Accept Sockets
81
+
82
+ [Socket]
83
+ ListenStream=0.0.0.0:9292
84
+ ListenStream=0.0.0.0:9293
85
+
86
+ # AF_UNIX domain socket
87
+ # SocketUser, SocketGroup, etc. may be needed for Unix domain sockets
88
+ # ListenStream=/run/puma.sock
89
+
90
+ # Socket options matching Puma defaults
91
+ NoDelay=true
92
+ ReusePort=true
93
+ Backlog=1024
94
+
95
+ [Install]
96
+ WantedBy=sockets.target
97
+ ~~~~
98
+
99
+ See [systemd.socket](https://www.freedesktop.org/software/systemd/man/systemd.socket.html)
100
+ for additional configuration details.
101
+
102
+ Note that the above configurations will work with Puma in either
103
+ single process or cluster mode.
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
+
115
+ ## Usage
116
+
117
+ Without socket activation, use `systemctl` as root (e.g. via `sudo`) as
118
+ with other system services:
119
+
120
+ ~~~~ sh
121
+ # After installing or making changes to puma.service
122
+ systemctl daemon-reload
123
+
124
+ # Enable so it starts on boot
125
+ systemctl enable puma.service
126
+
127
+ # Initial start up.
128
+ systemctl start puma.service
129
+
130
+ # Check status
131
+ systemctl status puma.service
132
+
133
+ # A normal restart. Warning: listeners sockets will be closed
134
+ # while a new puma process initializes.
135
+ systemctl restart puma.service
136
+ ~~~~
137
+
138
+ With socket activation, several but not all of these commands should
139
+ be run for both socket and service:
140
+
141
+ ~~~~ sh
142
+ # After installing or making changes to either puma.socket or
143
+ # puma.service.
144
+ systemctl daemon-reload
145
+
146
+ # Enable both socket and service so they start on boot. Alternatively
147
+ # you could leave puma.service disabled and systemd will start it on
148
+ # first use (with startup lag on first request)
149
+ systemctl enable puma.socket puma.service
150
+
151
+ # Initial start up. The Requires directive (see above) ensures the
152
+ # socket is started before the service.
153
+ systemctl start puma.socket puma.service
154
+
155
+ # Check status of both socket and service.
156
+ systemctl status puma.socket puma.service
157
+
158
+ # A "hot" restart, with systemd keeping puma.socket listening and
159
+ # providing to the new puma (master) instance.
160
+ systemctl restart puma.service
161
+
162
+ # A normal restart, needed to handle changes to
163
+ # puma.socket, such as changing the ListenStream ports. Note
164
+ # daemon-reload (above) should be run first.
165
+ systemctl restart puma.socket puma.service
166
+ ~~~~
167
+
168
+ Here is sample output from `systemctl status` with both service and
169
+ socket running:
170
+
171
+ ~~~~
172
+ ● puma.socket - Puma HTTP Server Accept Sockets
173
+ Loaded: loaded (/etc/systemd/system/puma.socket; enabled; vendor preset: enabled)
174
+ Active: active (running) since Thu 2016-04-07 08:40:19 PDT; 1h 2min ago
175
+ Listen: 0.0.0.0:9233 (Stream)
176
+ 0.0.0.0:9234 (Stream)
177
+
178
+ Apr 07 08:40:19 hx systemd[874]: Listening on Puma HTTP Server Accept Sockets.
179
+
180
+ ● puma.service - Puma HTTP Server
181
+ Loaded: loaded (/etc/systemd/system/puma.service; enabled; vendor preset: enabled)
182
+ Active: active (running) since Thu 2016-04-07 08:40:19 PDT; 1h 2min ago
183
+ Main PID: 28320 (ruby)
184
+ CGroup: /system.slice/puma.service
185
+ ├─28320 puma 3.3.0 (tcp://0.0.0.0:9233,ssl://0.0.0.0:9234?key=key.pem&cert=cert.pem) [app]
186
+ ├─28323 puma: cluster worker 0: 28320 [app]
187
+ └─28327 puma: cluster worker 1: 28320 [app]
188
+
189
+ Apr 07 08:40:19 hx puma[28320]: Puma starting in cluster mode...
190
+ Apr 07 08:40:19 hx puma[28320]: * Version 3.3.0 (ruby 2.2.4-p230), codename: Jovial Platypus
191
+ Apr 07 08:40:19 hx puma[28320]: * Min threads: 0, max threads: 16
192
+ Apr 07 08:40:19 hx puma[28320]: * Environment: production
193
+ Apr 07 08:40:19 hx puma[28320]: * Process workers: 2
194
+ Apr 07 08:40:19 hx puma[28320]: * Phased restart available
195
+ Apr 07 08:40:19 hx puma[28320]: * Activated tcp://0.0.0.0:9233
196
+ Apr 07 08:40:19 hx puma[28320]: * Activated ssl://0.0.0.0:9234?key=key.pem&cert=cert.pem
197
+ Apr 07 08:40:19 hx puma[28320]: Use Ctrl-C to stop
198
+ ~~~~
199
+
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
+ ### 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
@@ -3,6 +3,8 @@ require 'mkmf'
3
3
  dir_config("puma_http11")
4
4
 
5
5
  unless ENV["DISABLE_SSL"]
6
+ dir_config("openssl")
7
+
6
8
  if %w'crypto libeay32'.find {|crypto| have_library(crypto, 'BIO_read')} and
7
9
  %w'ssl ssleay32'.find {|ssl| have_library(ssl, 'SSL_CTX_new')}
8
10