-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfile.README.html
497 lines (327 loc) · 38.9 KB
/
file.README.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
<!DOCTYPE html>
<html>
<head>
<meta charset='UTF-8'>
<meta name='viewport' content='width=device-width, initial-scale=1.0, user-scalable=no'>
<meta name='apple-touch-fullscreen' content='yes'>
<meta name='apple-mobile-web-app-capable' content='yes'>
<meta name='apple-mobile-web-app-status-bar-style' content='rgba(228,228,228,1.0)'>
<title>File: README — Puma master</title>
<link rel='stylesheet' type='text/css' href='../css/y_fonts.css' />
<link rel='stylesheet' type='text/css' href='../css/highlight.github.css' />
<link rel='stylesheet' type='text/css' href='../css/y_style.css' />
<link rel='stylesheet' type='text/css' href='../css/y_list.css' />
<link rel='stylesheet' type='text/css' href='../css/y_color.css' />
<script type='text/javascript'>
var pathId = "README",
relpath = '';
var t2Info = {
CSEP: '.',
ISEP: '#',
NSEP: '::'
};
</script>
<script type='text/javascript' charset='utf-8' src='../js/highlight.pack.js'></script>
<script type='text/javascript' charset='utf-8' src='../js/y_app.js'></script>
</head>
<body>
<svg id='y_wait' class viewBox='0 0 90 90'></svg>
<div id='settings' class='hidden'></div>
<div id='y_list' class='d h'>
<header id='list_header'></header>
<nav id= 'list_nav' class='y_nav l_nav'>
<ul id='list_items'></ul>
</nav>
</div>
<div id='y_toc' class='f h'>
<header id='toc_header'></header>
<nav id= 'toc_nav' class='y_nav t_nav'>
<ol id='toc_items'></ol>
</nav>
</div>
<div id='y_main' tabindex='-1'>
<header id='y_header'>
<div id='y_menu'>
<a id='home_no_xhr' href='/'>Home</a> »
<a href='.'>Puma master</a> »
<a href='_index.html'>Index</a> »
<span class='title'><a id='t2_doc_top' href='#'>File: README ▲</a></span>
</div>
<a id='list_href' href="class_list.html"></a>
<div id='y_measure_em' class='y_measure'></div>
<div id='y_measure_vh' class='y_measure'></div>
<span id='y_measure_50pre' class='y_measure'><code>123456789_123456789_123456789_123456789_123456789_</code></span>
</header>
<div id='content' class='file'>
<p align="center">
<img src="https://puma.io/images/logos/puma-logo-large.png">
</p>
<h1>Puma: A Ruby Web Server Built For Parallelism</h1>
<p><a href="https://github.com/puma/puma/actions?query=workflow%3ATests"><img src="https://github.com/puma/puma/workflows/Tests/badge.svg?branch=master" alt="Actions"></a>
<a href="https://codeclimate.com/github/puma/puma"><img src="https://codeclimate.com/github/puma/puma.svg" alt="Code Climate"></a>
<a href="https://stackoverflow.com/questions/tagged/puma"><img src="https://img.shields.io/badge/stackoverflow-Puma-blue.svg" alt="StackOverflow"></a></p>
<p><a href="Puma.html" title="Puma (module)"><code>Puma</code></a> is a <strong>simple, fast, multi-threaded, and highly parallel HTTP 1.1 server for Ruby/Rack applications</strong>.</p>
<h2>Built For Speed & Parallelism</h2>
<p><a href="Puma.html" title="Puma (module)"><code>Puma</code></a> is a server for <a href="https://github.com/rack/rack">Rack</a>-powered HTTP applications written in Ruby. It is:</p>
<ul>
<li><strong>Multi-threaded</strong>. Each request is served in a separate thread. This helps you serve more requests per second with less memory use.</li>
<li><strong>Multi-process</strong>. "Pre-forks" in cluster mode, using less memory per-process thanks to copy-on-write memory.</li>
<li><strong>Standalone</strong>. With SSL support, zero-downtime rolling restarts and a built-in request bufferer, you can deploy <a href="Puma.html" title="Puma (module)"><code>Puma</code></a> without any reverse proxy.</li>
<li><strong>Battle-tested</strong>. Our HTTP parser is inherited from Mongrel and has over 15 years of production use. <a href="Puma.html" title="Puma (module)"><code>Puma</code></a> is currently the most popular Ruby webserver, and is the default server for Ruby on Rails.</li>
</ul>
<p>Originally designed as a server for <a href="https://github.com/rubinius/rubinius">Rubinius</a>, <a href="Puma.html" title="Puma (module)"><code>Puma</code></a> also works well with Ruby (MRI) and JRuby.</p>
<p>On MRI, there is a Global VM Lock (GVL) that ensures only one thread can run Ruby code at a time. But if you're doing a lot of blocking <a href="IO.html" title="IO (class)"><code>IO</code></a> (such as HTTP calls to external APIs like Twitter), <a href="Puma.html" title="Puma (module)"><code>Puma</code></a> still improves MRI's throughput by allowing <a href="IO.html" title="IO (class)"><code>IO</code></a> waiting to be done in parallel. Truly parallel Ruby implementations (TruffleRuby, JRuby) don't have this limitation.</p>
<h2>Quick Start</h2>
<pre class="code ruby"><code class="ruby"><span class='gvar'>$ </span><span class='id identifier rubyid_gem'>gem</span> <span class='id identifier rubyid_install'>install</span> <span class='id identifier rubyid_puma'>puma</span>
<span class='gvar'>$ </span><span class='id identifier rubyid_puma'>puma</span></code></pre>
<p>Without arguments, puma will look for a rackup (.ru) file in
working directory called <code>config.ru</code>.</p>
<h2>SSL Connection Support</h2>
<p>Puma will install/compile with support for ssl sockets, assuming OpenSSL
development files are installed on the system.</p>
<p>If the system does not have OpenSSL development files installed, Puma will
install/compile, but it will not allow ssl connections.</p>
<h2>Frameworks</h2>
<h3>Rails</h3>
<p>Puma is the default server for Rails, included in the generated Gemfile.</p>
<p>Start your server with the <code>rails</code> command:</p>
<pre class="code ruby"><code class="ruby"><span class='gvar'>$ </span><span class='id identifier rubyid_rails'>rails</span> <span class='id identifier rubyid_server'>server</span></code></pre>
<p>Many configuration options and Puma features are not available when using <code>rails server</code>. It is recommended that you use Puma's executable instead:</p>
<pre class="code ruby"><code class="ruby"><span class='gvar'>$ </span><span class='id identifier rubyid_bundle'>bundle</span> <span class='id identifier rubyid_exec'>exec</span> <span class='id identifier rubyid_puma'>puma</span></code></pre>
<h3>Sinatra</h3>
<p>You can run your Sinatra application with Puma from the command line like this:</p>
<pre class="code ruby"><code class="ruby"><span class='gvar'>$ </span><span class='id identifier rubyid_ruby'>ruby</span> <span class='id identifier rubyid_app'>app</span>.<span class='id identifier rubyid_rb'>rb</span> <span class='op'>-</span><span class='id identifier rubyid_s'>s</span> <span class='const'><a href="Puma.html" title="Puma (module)">Puma</a></span></code></pre>
<p>In order to actually configure Puma using a config file, like <code>puma.rb</code>, however, you need to use the <code>puma</code> executable. To do this, you must add a rackup file to your Sinatra app:</p>
<pre class="code ruby"><code class="ruby"><span class='comment'># config.ru
</span><span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>./app</span><span class='tstring_end'>'</span></span>
<span class='id identifier rubyid_run'>run</span> <span class='const'>Sinatra</span><span class='op'>::</span><span class='const'>Application</span></code></pre>
<p>You can then start your application using:</p>
<pre class="code ruby"><code class="ruby"><span class='gvar'>$ </span><span class='id identifier rubyid_bundle'>bundle</span> <span class='id identifier rubyid_exec'>exec</span> <span class='id identifier rubyid_puma'>puma</span></code></pre>
<h2>Configuration</h2>
<p>Puma provides numerous options. Consult <code>puma -h</code> (or <code>puma --help</code>) for a full list of CLI options, or see <a href="Puma/DSL.html" title="Puma::DSL (class)"><code>DSL</code></a> or <a href="https://github.com/puma/puma/blob/master/lib/puma/dsl.rb">dsl.rb</a>.</p>
<p>You can also find several configuration examples as part of the
<a href="https://github.com/puma/puma/tree/master/test/config">test</a> suite.</p>
<p>For debugging purposes, you can set the environment variable <code>PUMA_LOG_CONFIG</code> with a value
and the loaded configuration will be printed as part of the boot process.</p>
<h3>Thread Pool</h3>
<p>Puma uses a thread pool. You can set the minimum and maximum number of threads that are available in the pool with the <code>-t</code> (or <code>--threads</code>) flag:</p>
<pre class="code ruby"><code class="ruby"><span class='gvar'>$ </span><span class='id identifier rubyid_puma'>puma</span> <span class='op'>-</span><span class='id identifier rubyid_t'>t</span> <span class='int'>8</span><span class='symbeg'>:</span><span class='int'>32</span></code></pre>
<p>Puma will automatically scale the number of threads, from the minimum until it caps out at the maximum, based on how much traffic is present. The current default is <code>0:16</code> and on MRI is <code>0:5</code>. Feel free to experiment, but be careful not to set the number of maximum threads to a large number, as you may exhaust resources on the system (or cause contention for the Global VM Lock, when using MRI).</p>
<p>Be aware that additionally Puma creates threads on its own for internal purposes (e.g. handling slow clients). So, even if you specify -t 1:1, expect around 7 threads created in your application.</p>
<h3>Clustered mode</h3>
<p>Puma also offers "clustered mode". Clustered mode <code>fork</code>s workers from a master process. Each child process still has its own thread pool. You can tune the number of workers with the <code>-w</code> (or <code>--workers</code>) flag:</p>
<pre class="code ruby"><code class="ruby"><span class='gvar'>$ </span><span class='id identifier rubyid_puma'>puma</span> <span class='op'>-</span><span class='id identifier rubyid_t'>t</span> <span class='int'>8</span><span class='symbeg'>:</span><span class='int'>32</span> <span class='op'>-</span><span class='id identifier rubyid_w'>w</span> <span class='int'>3</span></code></pre>
<p>Or with the <code>WEB_CONCURRENCY</code> environment variable:</p>
<pre class="code ruby"><code class="ruby"><span class='gvar'>$ </span><span class='const'>WEB_CONCURRENCY</span><span class='op'>=</span><span class='int'>3</span> <span class='id identifier rubyid_puma'>puma</span> <span class='op'>-</span><span class='id identifier rubyid_t'>t</span> <span class='int'>8</span><span class='symbeg'>:</span><span class='int'>32</span></code></pre>
<p>Note that threads are still used in clustered mode, and the <code>-t</code> thread flag setting is per worker, so <code>-w 2 -t 16:16</code> will spawn 32 threads in total, with 16 in each worker process.</p>
<p>If the <code>WEB_CONCURRENCY</code> environment variable is set to <code>"auto"</code> and the <code>concurrent-ruby</code> gem is available in your application, Puma will set the worker process count to the result of <a href="https://ruby-concurrency.github.io/concurrent-ruby/master/Concurrent.html#available_processor_count-class_method">available processors</a>.</p>
<p>For an in-depth discussion of the tradeoffs of thread and process count settings, [see our docs]#workers-per-pod-and-other-config-issues).</p>
<p>In clustered mode, Puma can "preload" your application. This loads all the application code <em>prior</em> to forking. Preloading reduces total memory usage of your application via an operating system feature called <a href="https://en.wikipedia.org/wiki/Copy-on-write">copy-on-write</a>.</p>
<p>If the <code>WEB_CONCURRENCY</code> environment variable is set to a value > 1 (and <code>--prune-bundler</code> has not been specified), preloading will be enabled by default. Otherwise, you can use the <code>--preload</code> flag from the command line:</p>
<pre class="code ruby"><code class="ruby"><span class='gvar'>$ </span><span class='id identifier rubyid_puma'>puma</span> <span class='op'>-</span><span class='id identifier rubyid_w'>w</span> <span class='int'>3</span> <span class='op'>-</span><span class='op'>-</span><span class='id identifier rubyid_preload'>preload</span></code></pre>
<p>Or, if you're using a configuration file, you can use the <code>preload_app!</code> method:</p>
<pre class="code ruby"><code class="ruby"><span class='comment'># config/puma.rb
</span><span class='id identifier rubyid_workers'>workers</span> <span class='int'>3</span>
<span class='id identifier rubyid_preload_app!'>preload_app!</span></code></pre>
<p>Preloading can’t be used with phased restart, since phased restart kills and restarts workers one-by-one, and preloading copies the code of master into the workers.</p>
<h4>Clustered mode hooks</h4>
<p>When using clustered mode, Puma's configuration DSL provides <code>before_fork</code> and <code>on_worker_boot</code>
hooks to run code when the master process forks and child workers are booted respectively.</p>
<p>It is recommended to use these hooks with <code>preload_app!</code>, otherwise constants loaded by your
application (such as <code>Rails</code>) will not be available inside the hooks.</p>
<pre class="code ruby"><code class="ruby"><span class='comment'># config/puma.rb
</span><span class='id identifier rubyid_before_fork'>before_fork</span> <span class='kw'>do</span>
<span class='comment'># Add code to run inside the Puma master process before it forks a worker child.
</span><span class='kw'>end</span>
<span class='id identifier rubyid_on_worker_boot'>on_worker_boot</span> <span class='kw'>do</span>
<span class='comment'># Add code to run inside the Puma worker process after forking.
</span><span class='kw'>end</span></code></pre>
<p>In addition, there is an <code>on_refork</code> hook which is used only in <a href="file.fork_worker.html"><code>fork_worker</code> mode</a>,
when the worker 0 child process forks a grandchild worker:</p>
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_on_refork'>on_refork</span> <span class='kw'>do</span>
<span class='comment'># Used only when fork_worker mode is enabled. Add code to run inside the Puma worker 0
</span> <span class='comment'># child process before it forks a grandchild worker.
</span><span class='kw'>end</span></code></pre>
<p>Importantly, note the following considerations when Ruby forks a child process: </p>
<ol>
<li>File descriptors such as network sockets <strong>are</strong> copied from the parent to the forked
child process. Dual-use of the same sockets by parent and child will result in I/O conflicts
such as <code>SocketError</code>, <code>Errno::EPIPE</code>, and <code>EOFError</code>.</li>
<li>Background Ruby threads, including threads used by various third-party gems for connection
monitoring, etc., are <strong>not</strong> copied to the child process. Often this does not cause
immediate problems until a third-party connection goes down, at which point there will
be no supervisor to reconnect it.</li>
</ol>
<p>Therefore, we recommend the following:</p>
<ol>
<li>If possible, do not establish any socket connections (HTTP, database connections, etc.)
inside Puma's master process when booting.</li>
<li>If (1) is not possible, use <code>before_fork</code> and <code>on_refork</code> to disconnect the parent's socket
connections when forking, so that they are not accidentally copied to the child process.</li>
<li>Use <code>on_worker_boot</code> to restart any background threads on the forked child.</li>
</ol>
<h4>Master process lifecycle hooks</h4>
<p>Puma's configuration DSL provides master process lifecycle hooks <code>on_booted</code>, <code>on_restart</code>, and <code>on_stopped</code>
which may be used to specify code blocks to run on each event:</p>
<pre class="code ruby"><code class="ruby"><span class='comment'># config/puma.rb
</span><span class='id identifier rubyid_on_booted'>on_booted</span> <span class='kw'>do</span>
<span class='comment'># Add code to run in the Puma master process after it boots,
</span> <span class='comment'># and also after a phased restart completes.
</span><span class='kw'>end</span>
<span class='id identifier rubyid_on_restart'>on_restart</span> <span class='kw'>do</span>
<span class='comment'># Add code to run in the Puma master process when it receives
</span> <span class='comment'># a restart command but before it restarts.
</span><span class='kw'>end</span>
<span class='id identifier rubyid_on_stopped'>on_stopped</span> <span class='kw'>do</span>
<span class='comment'># Add code to run in the Puma master process when it receives
</span> <span class='comment'># a stop command but before it shuts down.
</span><span class='kw'>end</span></code></pre>
<h3>Error handling</h3>
<p>If Puma encounters an error outside of the context of your application, it will respond with a 400/500 and a simple
textual error message (see <a href="Puma/Server.html#lowlevel_error-instance_method" title="Puma::Server#lowlevel_error (method)">Puma::Server#lowlevel_error</a> or <a href="https://github.com/puma/puma/blob/master/lib/puma/server.rb">server.rb</a>).
You can specify custom behavior for this scenario. For example, you can report the error to your third-party
error-tracking service (in this example, <a href="https://rollbar.com">rollbar</a>):</p>
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_lowlevel_error_handler'>lowlevel_error_handler</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_e'>e</span><span class='comma'>,</span> <span class='id identifier rubyid_env'>env</span><span class='comma'>,</span> <span class='id identifier rubyid_status'>status</span><span class='op'>|</span>
<span class='kw'>if</span> <span class='id identifier rubyid_status'>status</span> <span class='op'>==</span> <span class='int'>400</span>
<span class='id identifier rubyid_message'>message</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>The server could not process the request due to an error, such as an incorrectly typed URL, malformed syntax, or a URL that contains illegal characters.\n</span><span class='tstring_end'>"</span></span>
<span class='kw'>else</span>
<span class='id identifier rubyid_message'>message</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>An error has occurred, and engineers have been informed. Please reload the page. If you continue to have problems, contact [email protected]\n</span><span class='tstring_end'>"</span></span>
<span class='const'>Rollbar</span>.<span class='id identifier rubyid_critical'>critical</span>(<span class='id identifier rubyid_e'>e</span>)
<span class='kw'>end</span>
[<span class='id identifier rubyid_status'>status</span><span class='comma'>,</span> {}<span class='comma'>,</span> [<span class='id identifier rubyid_message'>message</span>]]
<span class='kw'>end</span></code></pre>
<h3>Binding TCP / Sockets</h3>
<p>Bind Puma to a socket with the <code>-b</code> (or <code>--bind</code>) flag:</p>
<pre class="code ruby"><code class="ruby"><span class='gvar'>$ </span><span class='id identifier rubyid_puma'>puma</span> <span class='op'>-</span><span class='id identifier rubyid_b'>b</span> <span class='label'>tcp:</span><span class='tstring'><span class='regexp_beg'>/</span><span class='regexp_end'>/</span></span><span class='float'>127.0</span><span class='op'>:</span><span class='int'>9292</span></code></pre>
<p>To use a UNIX Socket instead of TCP:</p>
<pre class="code ruby"><code class="ruby"><span class='gvar'>$ </span><span class='id identifier rubyid_puma'>puma</span> <span class='op'>-</span><span class='id identifier rubyid_b'>b</span> <span class='label'>unix:</span><span class='tstring'><span class='regexp_beg'>/</span><span class='regexp_end'>/</span></span><span class='op'>/</span><span class='id identifier rubyid_var'>var</span><span class='op'>/</span><span class='id identifier rubyid_run'>run</span><span class='op'>/</span><span class='id identifier rubyid_puma'>puma</span>.<span class='id identifier rubyid_sock'>sock</span></code></pre>
<p>If you need to change the permissions of the UNIX socket, just add a umask parameter:</p>
<pre class="code ruby"><code class="ruby"><span class='gvar'>$ </span><span class='id identifier rubyid_puma'>puma</span> <span class='op'>-</span><span class='id identifier rubyid_b'>b</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>unix:///var/run/puma.sock?umask=0111</span><span class='tstring_end'>'</span></span></code></pre>
<p>Need a bit of security? Use SSL sockets:</p>
<pre class="code ruby"><code class="ruby"><span class='gvar'>$ </span><span class='id identifier rubyid_puma'>puma</span> <span class='op'>-</span><span class='id identifier rubyid_b'>b</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>ssl://127.0.0.1:9292?key=path_to_key&cert=path_to_cert</span><span class='tstring_end'>'</span></span></code></pre>
<h4>Self-signed SSL certificates (via the <a href="https://github.com/socketry/localhost"><code>localhost</code></a> gem, for development use):</h4>
<p>Puma supports the <a href="https://github.com/socketry/localhost"><code>localhost</code></a> gem for self-signed certificates. This is particularly useful if you want to use Puma with SSL locally, and self-signed certificates will work for your use-case. Currently, the integration can only be used in MRI.</p>
<p>Puma automatically configures SSL when the <a href="https://github.com/socketry/localhost"><code>localhost</code></a> gem is loaded in a <code>development</code> environment:</p>
<p>Add the gem to your Gemfile:</p>
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_group'>group</span>(<span class='symbeg'>:</span><span class='id identifier rubyid_development'>development</span>) <span class='kw'>do</span>
<span class='id identifier rubyid_gem'>gem</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>localhost</span><span class='tstring_end'>'</span></span>
<span class='kw'>end</span></code></pre>
<p>And require it implicitly using bundler:</p>
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>bundler</span><span class='tstring_end'>"</span></span>
<span class='const'>Bundler</span>.<span class='id identifier rubyid_require'>require</span>(<span class='symbeg'>:</span><span class='id identifier rubyid_default'>default</span><span class='comma'>,</span> <span class='const'>ENV</span>[<span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>RACK_ENV</span><span class='tstring_end'>"</span></span>].<span class='id identifier rubyid_to_sym'>to_sym</span>)</code></pre>
<p>Alternatively, you can require the gem in your configuration file, either <code>config/puma/development.rb</code>, <code>config/puma.rb</code>, or set via the <code>-C</code> cli option:</p>
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>localhost</span><span class='tstring_end'>'</span></span>
<span class='comment'># configuration methods (from Puma::DSL) as needed</span></code></pre>
<p>Additionally, Puma must be listening to an SSL socket:</p>
<pre class="code shell"><code class="shell">$ puma -b 'ssl://localhost:9292' -C config/use_local_host.rb
# The following options allow you to reach Puma over HTTP as well:
$ puma -b ssl://localhost:9292 -b tcp://localhost:9393 -C config/use_local_host.rb
</code></pre>
<h4>Controlling SSL Cipher Suites</h4>
<p>To use or avoid specific SSL ciphers for TLSv1.2 and below, use <code>ssl_cipher_filter</code> or <code>ssl_cipher_list</code> options.</p>
<h5>Ruby:</h5>
<pre class="code ruby"><code class="ruby"><span class='gvar'>$ </span><span class='id identifier rubyid_puma'>puma</span> <span class='op'>-</span><span class='id identifier rubyid_b'>b</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>ssl://127.0.0.1:9292?key=path_to_key&cert=path_to_cert&ssl_cipher_filter=!aNULL:AES+SHA</span><span class='tstring_end'>'</span></span></code></pre>
<h5>JRuby:</h5>
<pre class="code ruby"><code class="ruby"><span class='gvar'>$ </span><span class='id identifier rubyid_puma'>puma</span> <span class='op'>-</span><span class='id identifier rubyid_b'>b</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>ssl://127.0.0.1:9292?keystore=path_to_keystore&keystore-pass=keystore_password&ssl_cipher_list=TLS_RSA_WITH_AES_128_CBC_SHA,TLS_RSA_WITH_AES_256_CBC_SHA</span><span class='tstring_end'>'</span></span></code></pre>
<p>To configure the available TLSv1.3 ciphersuites, use <code>ssl_ciphersuites</code> option (not available for JRuby).</p>
<h5>Ruby:</h5>
<pre class="code ruby"><code class="ruby"><span class='gvar'>$ </span><span class='id identifier rubyid_puma'>puma</span> <span class='op'>-</span><span class='id identifier rubyid_b'>b</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>ssl://127.0.0.1:9292?key=path_to_key&cert=path_to_cert&ssl_ciphersuites=TLS_AES_256_GCM_SHA384:TLS_AES_128_GCM_SHA256</span><span class='tstring_end'>'</span></span></code></pre>
<p>See <a href="https://www.openssl.org/docs/man1.1.1/man1/ciphers.html">https://www.openssl.org/docs/man1.1.1/man1/ciphers.html</a> for cipher filter format and full list of cipher suites.</p>
<p>Disable TLS v1 with the <code>no_tlsv1</code> option:</p>
<pre class="code ruby"><code class="ruby"><span class='gvar'>$ </span><span class='id identifier rubyid_puma'>puma</span> <span class='op'>-</span><span class='id identifier rubyid_b'>b</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>ssl://127.0.0.1:9292?key=path_to_key&cert=path_to_cert&no_tlsv1=true</span><span class='tstring_end'>'</span></span></code></pre>
<h4>Controlling OpenSSL Verification Flags</h4>
<p>To enable verification flags offered by OpenSSL, use <code>verification_flags</code> (not available for JRuby):</p>
<pre class="code ruby"><code class="ruby"><span class='gvar'>$ </span><span class='id identifier rubyid_puma'>puma</span> <span class='op'>-</span><span class='id identifier rubyid_b'>b</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>ssl://127.0.0.1:9292?key=path_to_key&cert=path_to_cert&verification_flags=PARTIAL_CHAIN</span><span class='tstring_end'>'</span></span></code></pre>
<p>You can also set multiple verification flags (by separating them with a comma):</p>
<pre class="code ruby"><code class="ruby"><span class='gvar'>$ </span><span class='id identifier rubyid_puma'>puma</span> <span class='op'>-</span><span class='id identifier rubyid_b'>b</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>ssl://127.0.0.1:9292?key=path_to_key&cert=path_to_cert&verification_flags=PARTIAL_CHAIN,CRL_CHECK</span><span class='tstring_end'>'</span></span></code></pre>
<p>List of available flags: <code>USE_CHECK_TIME</code>, <code>CRL_CHECK</code>, <code>CRL_CHECK_ALL</code>, <code>IGNORE_CRITICAL</code>, <code>X509_STRICT</code>, <code>ALLOW_PROXY_CERTS</code>, <code>POLICY_CHECK</code>, <code>EXPLICIT_POLICY</code>, <code>INHIBIT_ANY</code>, <code>INHIBIT_MAP</code>, <code>NOTIFY_POLICY</code>, <code>EXTENDED_CRL_SUPPORT</code>, <code>USE_DELTAS</code>, <code>CHECK_SS_SIGNATURE</code>, <code>TRUSTED_FIRST</code>, <code>SUITEB_128_LOS_ONLY</code>, <code>SUITEB_192_LOS</code>, <code>SUITEB_128_LOS</code>, <code>PARTIAL_CHAIN</code>, <code>NO_ALT_CHAINS</code>, <code>NO_CHECK_TIME</code>
(see <a href="https://www.openssl.org/docs/manmaster/man3/X509_VERIFY_PARAM_set_hostflags.html#VERIFICATION-FLAGS">https://www.openssl.org/docs/manmaster/man3/X509_VERIFY_PARAM_set_hostflags.html#VERIFICATION-FLAGS</a>).</p>
<h4>Controlling OpenSSL Password Decryption</h4>
<p>To enable runtime decryption of an encrypted SSL key (not available for JRuby), use <code>key_password_command</code>:</p>
<pre class="code ruby"><code class="ruby"><span class='gvar'>$ </span><span class='id identifier rubyid_puma'>puma</span> <span class='op'>-</span><span class='id identifier rubyid_b'>b</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>ssl://127.0.0.1:9292?key=path_to_key&cert=path_to_cert&key_password_command=/path/to/command.sh</span><span class='tstring_end'>'</span></span></code></pre>
<p><code>key_password_command</code> must:</p>
<ol>
<li>Be executable by Puma.</li>
<li>Print the decryption password to stdout.</li>
</ol>
<p>For example:</p>
<pre class="code shell"><code class="shell">#!/bin/sh
echo "this is my password"
</code></pre>
<p><code>key_password_command</code> can be used with <code>key</code> or <code>key_pem</code>. If the key
is not encrypted, the executable will not be called.</p>
<h3>Control/Status Server</h3>
<p>Puma has a built-in status and control app that can be used to query and control Puma.</p>
<pre class="code ruby"><code class="ruby"><span class='gvar'>$ </span><span class='id identifier rubyid_puma'>puma</span> <span class='op'>-</span><span class='op'>-</span><span class='id identifier rubyid_control'>control</span><span class='op'>-</span><span class='id identifier rubyid_url'>url</span> <span class='label'>tcp:</span><span class='tstring'><span class='regexp_beg'>/</span><span class='regexp_end'>/</span></span><span class='float'>127.0</span><span class='op'>:</span><span class='int'>9293</span> <span class='op'>-</span><span class='op'>-</span><span class='id identifier rubyid_control'>control</span><span class='op'>-</span><span class='id identifier rubyid_token'>token</span> <span class='id identifier rubyid_foo'>foo</span></code></pre>
<p>Puma will start the control server on localhost port 9293. All requests to the control server will need to include control token (in this case, <code>token=foo</code>) as a query parameter. This allows for simple authentication. Check out <a href="Puma/App/Status.html" title="Puma::App::Status (class)"><code>App::Status</code></a> or <a href="https://github.com/puma/puma/blob/master/lib/puma/app/status.rb">status.rb</a> to see what the status app has available.</p>
<p>You can also interact with the control server via <code>pumactl</code>. This command will restart Puma:</p>
<pre class="code ruby"><code class="ruby"><span class='gvar'>$ </span><span class='id identifier rubyid_pumactl'>pumactl</span> <span class='op'>-</span><span class='op'>-</span><span class='id identifier rubyid_control'>control</span><span class='op'>-</span><span class='id identifier rubyid_url'>url</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>tcp://127.0.0.1:9293</span><span class='tstring_end'>'</span></span> <span class='op'>-</span><span class='op'>-</span><span class='id identifier rubyid_control'>control</span><span class='op'>-</span><span class='id identifier rubyid_token'>token</span> <span class='id identifier rubyid_foo'>foo</span> <span class='id identifier rubyid_restart'>restart</span></code></pre>
<p>To see a list of <code>pumactl</code> options, use <code>pumactl --help</code>.</p>
<h3>Configuration File</h3>
<p>You can also provide a configuration file with the <code>-C</code> (or <code>--config</code>) flag:</p>
<pre class="code ruby"><code class="ruby"><span class='gvar'>$ </span><span class='id identifier rubyid_puma'>puma</span> <span class='op'>-</span><span class='const'>C</span> <span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>path</span><span class='regexp_end'>/to</span></span><span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>config</span></code></pre>
<p>If no configuration file is specified, Puma will look for a configuration file at <code>config/puma.rb</code>. If an environment is specified (via the <code>--environment</code> flag or through the <code>APP_ENV</code>, <code>RACK_ENV</code>, or <code>RAILS_ENV</code> environment variables) Puma looks for a configuration file at <code>config/puma/<environment_name>.rb</code> and then falls back to <code>config/puma.rb</code>.</p>
<p>If you want to prevent Puma from looking for a configuration file in those locations, include the <code>--no-config</code> flag:</p>
<pre class="code ruby"><code class="ruby"><span class='gvar'>$ </span><span class='id identifier rubyid_puma'>puma</span> <span class='op'>-</span><span class='op'>-</span><span class='id identifier rubyid_no'>no</span><span class='op'>-</span><span class='id identifier rubyid_config'>config</span>
<span class='comment'># or
</span>
<span class='gvar'>$ </span><span class='id identifier rubyid_puma'>puma</span> <span class='op'>-</span><span class='const'>C</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>-</span><span class='tstring_end'>"</span></span></code></pre>
<p>The other side-effects of setting the environment are whether to show stack traces (in <code>development</code> or <code>test</code>), and setting RACK_ENV may potentially affect middleware looking for this value to change their behavior. The default puma RACK_ENV value is <code>development</code>. You can see all config default values in <a href="Puma/Configuration.html#puma_default_options-instance_method" title="Puma::Configuration#puma_default_options (method)">Puma::Configuration#puma_default_options</a> or <a href="https://github.com/puma/puma/blob/61c6213fbab/lib/puma/configuration.rb#L182-L204">configuration.rb</a>.</p>
<p>Check out <a href="Puma/DSL.html" title="Puma::DSL (class)"><code>DSL</code></a> or <a href="https://github.com/puma/puma/blob/master/lib/puma/dsl.rb">dsl.rb</a> to see all available options.</p>
<h2>Restart</h2>
<p>Puma includes the ability to restart itself. When available (MRI, Rubinius, JRuby), Puma performs a "hot restart". This is the same functionality available in <em>Unicorn</em> and <em>NGINX</em> which keep the server sockets open between restarts. This makes sure that no pending requests are dropped while the restart is taking place.</p>
<p>For more, see the <a href="file.restart.html">Restart documentation</a>.</p>
<h2>Signals</h2>
<p>Puma responds to several signals. A detailed guide to using UNIX signals with Puma can be found in the <a href="file.signals.html">Signals documentation</a>.</p>
<h2>Platform Constraints</h2>
<p>Some platforms do not support all Puma features.</p>
<ul>
<li><strong>JRuby</strong>, <strong>Windows</strong>: server sockets are not seamless on restart, they must be closed and reopened. These platforms have no way to pass descriptors into a new process that is exposed to Ruby. Also, cluster mode is not supported due to a lack of fork(2).</li>
<li><strong>Windows</strong>: Cluster mode is not supported due to a lack of fork(2).</li>
<li><strong>Kubernetes</strong>: The way Kubernetes handles pod shutdowns interacts poorly with server processes implementing graceful shutdown, like Puma. See the <a href="file.kubernetes.html">kubernetes section of the documentation</a> for more details.</li>
</ul>
<h2>Known Bugs</h2>
<p>For MRI versions 2.2.7, 2.2.8, 2.2.9, 2.2.10, 2.3.4 and 2.4.1, you may see <code>stream closed in another thread (IOError)</code>. It may be caused by a <a href="https://bugs.ruby-lang.org/issues/13632">Ruby bug</a>. It can be fixed with the gem <a href="https://rubygems.org/gems/stopgap_13632:">https://rubygems.org/gems/stopgap_13632:</a></p>
<pre class="code ruby"><code class="ruby"><span class='kw'>if</span> <span class='qwords'><span class='qwords_beg'>%w(</span><span class='tstring_content'>2.2.7</span><span class='words_sep'> </span><span class='tstring_content'>2.2.8</span><span class='words_sep'> </span><span class='tstring_content'>2.2.9</span><span class='words_sep'> </span><span class='tstring_content'>2.2.10</span><span class='words_sep'> </span><span class='tstring_content'>2.3.4</span><span class='words_sep'> </span><span class='tstring_content'>2.4.1</span><span class='tstring_end'>)</span></span>.<span class='id identifier rubyid_include?'>include?</span> <span class='const'>RUBY_VERSION</span>
<span class='kw'>begin</span>
<span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>stopgap_13632</span><span class='tstring_end'>'</span></span>
<span class='kw'>rescue</span> <span class='const'>LoadError</span>
<span class='kw'>end</span>
<span class='kw'>end</span></code></pre>
<h2>Deployment</h2>
<ul>
<li><p>Puma has support for Capistrano with an <a href="https://github.com/seuros/capistrano-puma">external gem</a>.</p></li>
<li><p>Additionally, Puma has support for built-in daemonization via the <a href="https://github.com/kigster/puma-daemon">puma-daemon</a> ruby gem. The gem restores the <code>daemonize</code> option that was removed from Puma starting version 5, but only for MRI Ruby.</p></li>
</ul>
<p>It is common to use process monitors with Puma. Modern process monitors like systemd or rc.d
provide continuous monitoring and restarts for increased reliability in production environments:</p>
<ul>
<li><a href="file.README.html">rc.d</a></li>
<li><a href="file.systemd.html">systemd</a></li>
</ul>
<p>Community guides:</p>
<ul>
<li><a href="https://gist.github.com/anon987654321/4532cf8d6c59c1f43ec8973faa031103">Deploying Puma on OpenBSD using relayd and httpd</a></li>
</ul>
<h2>Community Extensions</h2>
<h3>Plugins</h3>
<ul>
<li><a href="https://github.com/harmjanblok/puma-metrics">puma-metrics</a> — export Puma metrics to Prometheus</li>
<li><a href="https://github.com/yob/puma-plugin-statsd">puma-plugin-statsd</a> — send Puma metrics to statsd</li>
<li><a href="https://github.com/sj26/puma-plugin-systemd">puma-plugin-systemd</a> — deeper integration with systemd for notify, status and watchdog. Puma 5.1.0 integrated notify and watchdog, which probably conflicts with this plugin. Puma 6.1.0 added status support which obsoletes the plugin entirely.</li>
<li><a href="https://github.com/babbel/puma-plugin-telemetry">puma-plugin-telemetry</a> - telemetry plugin for Puma offering various targets to publish</li>
<li><a href="https://github.com/anchordotdev/puma-acme">puma-acme</a> - automatic SSL/HTTPS certificate provisioning and setup</li>
</ul>
<h3>Monitoring</h3>
<ul>
<li><a href="https://github.com/ylecuyer/puma-status">puma-status</a> — Monitor CPU/Mem/Load of running puma instances from the CLI</li>
</ul>
<h2>Contributing</h2>
<p>Find details for contributing in the <a href="file.CONTRIBUTING.html">contribution guide</a>.</p>
<h2>License</h2>
<p>Puma is copyright Evan Phoenix and contributors, licensed under the BSD 3-Clause license. See the included LICENSE file for details.</p>
<div id='footer'></div>
</div> <!-- content -->
</div> <!-- y_main -->
</body>
</html>