puma 2.0.0.b5 → 5.0.0.beta1

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 (106) hide show
  1. checksums.yaml +7 -0
  2. data/History.md +1598 -0
  3. data/LICENSE +23 -20
  4. data/README.md +222 -62
  5. data/bin/puma-wild +31 -0
  6. data/bin/pumactl +1 -1
  7. data/docs/architecture.md +37 -0
  8. data/docs/deployment.md +113 -0
  9. data/docs/fork_worker.md +31 -0
  10. data/docs/images/puma-connection-flow-no-reactor.png +0 -0
  11. data/docs/images/puma-connection-flow.png +0 -0
  12. data/docs/images/puma-general-arch.png +0 -0
  13. data/docs/jungle/README.md +13 -0
  14. data/docs/jungle/rc.d/README.md +74 -0
  15. data/docs/jungle/rc.d/puma +61 -0
  16. data/docs/jungle/rc.d/puma.conf +10 -0
  17. data/docs/jungle/upstart/README.md +61 -0
  18. data/docs/jungle/upstart/puma-manager.conf +31 -0
  19. data/docs/jungle/upstart/puma.conf +69 -0
  20. data/docs/nginx.md +5 -10
  21. data/docs/plugins.md +38 -0
  22. data/docs/restart.md +41 -0
  23. data/docs/signals.md +97 -0
  24. data/docs/systemd.md +228 -0
  25. data/ext/puma_http11/PumaHttp11Service.java +2 -2
  26. data/ext/puma_http11/extconf.rb +23 -2
  27. data/ext/puma_http11/http11_parser.c +301 -482
  28. data/ext/puma_http11/http11_parser.h +13 -11
  29. data/ext/puma_http11/http11_parser.java.rl +26 -42
  30. data/ext/puma_http11/http11_parser.rl +22 -21
  31. data/ext/puma_http11/http11_parser_common.rl +5 -5
  32. data/ext/puma_http11/mini_ssl.c +377 -18
  33. data/ext/puma_http11/org/jruby/puma/Http11.java +108 -107
  34. data/ext/puma_http11/org/jruby/puma/Http11Parser.java +137 -170
  35. data/ext/puma_http11/org/jruby/puma/MiniSSL.java +265 -191
  36. data/ext/puma_http11/puma_http11.c +57 -81
  37. data/lib/puma.rb +25 -4
  38. data/lib/puma/accept_nonblock.rb +7 -1
  39. data/lib/puma/app/status.rb +61 -24
  40. data/lib/puma/binder.rb +212 -78
  41. data/lib/puma/cli.rb +149 -644
  42. data/lib/puma/client.rb +316 -65
  43. data/lib/puma/cluster.rb +659 -0
  44. data/lib/puma/commonlogger.rb +108 -0
  45. data/lib/puma/configuration.rb +279 -180
  46. data/lib/puma/const.rb +126 -39
  47. data/lib/puma/control_cli.rb +183 -96
  48. data/lib/puma/detect.rb +20 -1
  49. data/lib/puma/dsl.rb +776 -0
  50. data/lib/puma/events.rb +91 -23
  51. data/lib/puma/io_buffer.rb +9 -5
  52. data/lib/puma/jruby_restart.rb +9 -5
  53. data/lib/puma/launcher.rb +487 -0
  54. data/lib/puma/minissl.rb +239 -93
  55. data/lib/puma/minissl/context_builder.rb +76 -0
  56. data/lib/puma/null_io.rb +22 -12
  57. data/lib/puma/plugin.rb +111 -0
  58. data/lib/puma/plugin/tmp_restart.rb +36 -0
  59. data/lib/puma/rack/builder.rb +297 -0
  60. data/lib/puma/rack/urlmap.rb +93 -0
  61. data/lib/puma/rack_default.rb +9 -0
  62. data/lib/puma/reactor.rb +290 -43
  63. data/lib/puma/runner.rb +163 -0
  64. data/lib/puma/server.rb +493 -126
  65. data/lib/puma/single.rb +66 -0
  66. data/lib/puma/state_file.rb +34 -0
  67. data/lib/puma/thread_pool.rb +228 -47
  68. data/lib/puma/util.rb +115 -0
  69. data/lib/rack/handler/puma.rb +78 -31
  70. data/tools/Dockerfile +16 -0
  71. data/tools/trickletest.rb +44 -0
  72. metadata +60 -155
  73. data/COPYING +0 -55
  74. data/Gemfile +0 -8
  75. data/History.txt +0 -196
  76. data/Manifest.txt +0 -56
  77. data/Rakefile +0 -121
  78. data/TODO +0 -5
  79. data/docs/config.md +0 -0
  80. data/ext/puma_http11/io_buffer.c +0 -154
  81. data/lib/puma/capistrano.rb +0 -26
  82. data/lib/puma/compat.rb +0 -11
  83. data/lib/puma/daemon_ext.rb +0 -20
  84. data/lib/puma/delegation.rb +0 -11
  85. data/lib/puma/java_io_buffer.rb +0 -45
  86. data/lib/puma/rack_patch.rb +0 -25
  87. data/puma.gemspec +0 -45
  88. data/test/test_app_status.rb +0 -88
  89. data/test/test_cli.rb +0 -171
  90. data/test/test_config.rb +0 -16
  91. data/test/test_http10.rb +0 -27
  92. data/test/test_http11.rb +0 -126
  93. data/test/test_integration.rb +0 -150
  94. data/test/test_iobuffer.rb +0 -38
  95. data/test/test_minissl.rb +0 -22
  96. data/test/test_null_io.rb +0 -31
  97. data/test/test_persistent.rb +0 -238
  98. data/test/test_puma_server.rb +0 -128
  99. data/test/test_rack_handler.rb +0 -10
  100. data/test/test_rack_server.rb +0 -141
  101. data/test/test_thread_pool.rb +0 -146
  102. data/test/test_unix_socket.rb +0 -39
  103. data/test/test_ws.rb +0 -89
  104. data/tools/jungle/README.md +0 -54
  105. data/tools/jungle/puma +0 -332
  106. data/tools/jungle/run-puma +0 -3
data/LICENSE CHANGED
@@ -1,26 +1,29 @@
1
- Some code copyright (c) 2005, Zed Shaw
2
- Copyright (c) 2011, Evan Phoenix
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2019, Evan Phoenix. Some code by Zed Shaw, (c) 2005.
3
4
  All rights reserved.
4
5
 
5
- Redistribution and use in source and binary forms, with or without
6
+ Redistribution and use in source and binary forms, with or without
6
7
  modification, are permitted provided that the following conditions are met:
7
8
 
8
- * Redistributions of source code must retain the above copyright notice, this
9
- list of conditions and the following disclaimer.
10
- * Redistributions in binary form must reproduce the above copyright notice
11
- this list of conditions and the following disclaimer in the documentation
12
- and/or other materials provided with the distribution.
13
- * Neither the name of the Evan Phoenix nor the names of its contributors
14
- may be used to endorse or promote products derived from this software
15
- without specific prior written permission.
9
+ 1. Redistributions of source code must retain the above copyright notice, this
10
+ list of conditions and the following disclaimer.
11
+
12
+ 2. Redistributions in binary form must reproduce the above copyright notice,
13
+ this list of conditions and the following disclaimer in the documentation
14
+ and/or other materials provided with the distribution.
15
+
16
+ 3. Neither the name of the copyright holder nor the names of its
17
+ contributors may be used to endorse or promote products derived from
18
+ this software without specific prior written permission.
16
19
 
17
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18
- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20
- DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
21
- FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22
- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23
- SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24
- CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25
- OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
20
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26
29
  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md CHANGED
@@ -1,137 +1,297 @@
1
+ <p align="center">
2
+ <img src="https://puma.io/images/logos/puma-logo-large.png">
3
+ </p>
4
+
1
5
  # Puma: A Ruby Web Server Built For Concurrency
2
6
 
3
- [![Build Status](https://secure.travis-ci.org/puma/puma.png)](http://travis-ci.org/puma/puma) [![Dependency Status](https://gemnasium.com/puma/puma.png)](https://gemnasium.com/puma/puma)
7
+ [![Actions Build Status](https://github.com/puma/puma/workflows/CI/badge.svg?branch=master)](https://github.com/puma/puma/actions)
8
+
9
+ [![Code Climate](https://codeclimate.com/github/puma/puma.svg)](https://codeclimate.com/github/puma/puma)
10
+ [![SemVer](https://api.dependabot.com/badges/compatibility_score?dependency-name=puma&package-manager=bundler&version-scheme=semver)](https://dependabot.com/compatibility-score.html?dependency-name=puma&package-manager=bundler&version-scheme=semver)
11
+ [![StackOverflow](http://img.shields.io/badge/stackoverflow-Puma-blue.svg)]( http://stackoverflow.com/questions/tagged/puma )
4
12
 
5
- ## Description
13
+ Puma is a **simple, fast, multi-threaded, and highly concurrent HTTP 1.1 server for Ruby/Rack applications**.
6
14
 
7
- Puma is a simple, fast, and highly concurrent HTTP 1.1 server for Ruby web applications. It can be used with any application that supports Rack, and is considered the replacement for Webrick and Mongrel. It was designed to be the go-to server for [Rubinius](http://rubini.us), but also works well with JRuby and MRI. Puma is intended for use in both development and production environments.
15
+ ## Built For Speed &amp; Concurrency
8
16
 
9
- Under the hood, Puma processes requests using a C-optimized Ragel extension (inherited from Mongrel) that provides fast, accurate HTTP 1.1 protocol parsing in a portable way. Puma then serves the request in a thread from an internal thread pool (which you can control). This allows Puma to provide real concurrency for your web application!
17
+ Puma processes requests using a C-optimized Ragel extension (inherited from Mongrel) that provides fast, accurate HTTP 1.1 protocol parsing in a portable way. Puma then serves the request using a thread pool. Each request is served in a separate thread, so truly concurrent Ruby implementations (JRuby, Rubinius) will use all available CPU cores.
10
18
 
11
- With Rubinius 2.0, Puma will utilize all cores on your CPU with real threads, meaning you won't have to spawn multiple processes to increase throughput. You can expect to see a similar benefit from JRuby.
19
+ Puma was designed to be the go-to server for [Rubinius](https://rubinius.com), but also works well with JRuby and MRI.
12
20
 
13
- On MRI, there is a Global Interpreter Lock (GIL) that ensures only one thread can be run at a time. But if you're doing a lot of blocking IO (such as HTTP calls to external APIs like Twitter), Puma still improves MRI's throughput by allowing blocking IO to be run concurrently (EventMachine-based servers such as Thin turn off this ability, requiring you to use special libraries). Your mileage may vary. In order to get the best throughput, it is highly recommended that you use a Ruby implementation with real threads like [Rubinius](http://rubini.us) or [JRuby](http://jruby.org).
21
+ 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 IO (such as HTTP calls to external APIs like Twitter), Puma still improves MRI's throughput by allowing IO waiting to be done in parallel.
14
22
 
15
23
  ## Quick Start
16
24
 
17
- The easiest way to get started with Puma is to install it via RubyGems. You can do this easily:
25
+ ```
26
+ $ gem install puma
27
+ $ puma
28
+ ```
29
+
30
+ Without arguments, puma will look for a rackup (.ru) file in
31
+ working directory called `config.ru`.
32
+
33
+ ## Frameworks
34
+
35
+ ### Rails
36
+
37
+ Puma is the default server for Rails, included in the generated Gemfile.
18
38
 
19
- $ gem install puma
39
+ Start your server with the `rails` command:
20
40
 
21
- Now you should have the puma command available in your PATH, so just do the following in the root folder of your Rack application:
41
+ ```
42
+ $ rails server
43
+ ```
22
44
 
23
- $ puma app.ru
45
+ Many configuration options and Puma features are not available when using `rails server`. It is recommended that you use Puma's executable instead:
24
46
 
25
- ## Advanced Setup
47
+ ```
48
+ $ bundle exec puma
49
+ ```
26
50
 
27
51
  ### Sinatra
28
52
 
29
53
  You can run your Sinatra application with Puma from the command line like this:
30
54
 
31
- $ ruby app.rb -s Puma
55
+ ```
56
+ $ ruby app.rb -s Puma
57
+ ```
32
58
 
33
- Or you can configure your application to always use Puma:
59
+ Or you can configure your Sinatra application to always use Puma:
34
60
 
35
- require 'sinatra'
36
- configure { set :server, :puma }
61
+ ```ruby
62
+ require 'sinatra'
63
+ configure { set :server, :puma }
64
+ ```
37
65
 
38
- If you use Bundler, make sure you add Puma to your Gemfile (see below).
66
+ ## Configuration
39
67
 
40
- ### Rails
68
+ Puma provides numerous options. Consult `puma -h` (or `puma --help`) for a full list of CLI options, or see [dsl.rb](https://github.com/puma/puma/blob/master/lib/puma/dsl.rb).
41
69
 
42
- First, make sure Puma is in your Gemfile:
70
+ You can also find several configuration examples as part of the
71
+ [test](https://github.com/puma/puma/tree/master/test/config) suite.
43
72
 
44
- gem 'puma'
73
+ ### Thread Pool
45
74
 
46
- Then start your server with the `rails` command:
75
+ Puma uses a thread pool. You can set the minimum and maximum number of threads that are available in the pool with the `-t` (or `--threads`) flag:
47
76
 
48
- $ rails s Puma
77
+ ```
78
+ $ puma -t 8:32
79
+ ```
49
80
 
50
- ### Rackup
81
+ 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 `0:16` and on MRI is `0:5`. 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).
51
82
 
52
- You can pass it as an option to `rackup`:
83
+ 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.
53
84
 
54
- $ rackup -s puma
85
+ ### Clustered mode
55
86
 
56
- Alternatively, you can modify your `config.ru` to choose Puma by default, by adding the following as the first line:
87
+ Puma also offers "clustered mode". Clustered mode `fork`s workers from a master process. Each child process still has its own thread pool. You can tune the number of workers with the `-w` (or `--workers`) flag:
57
88
 
58
- #\ -s puma
89
+ ```
90
+ $ puma -t 8:32 -w 3
91
+ ```
59
92
 
60
- ## Configuration
93
+ Note that threads are still used in clustered mode, and the `-t` thread flag setting is per worker, so `-w 2 -t 16:16` will spawn 32 threads in total, with 16 in each worker process.
61
94
 
62
- Puma provides numerous options for controlling the operation of the server. Consult `puma -h` (or `puma --help`) for a full list.
95
+ In clustered mode, Puma can "preload" your application. This loads all the application code *prior* to forking. Preloading reduces total memory usage of your application via an operating system feature called [copy-on-write](https://en.wikipedia.org/wiki/Copy-on-write) (Ruby 2.0+ only). Use the `--preload` flag from the command line:
63
96
 
64
- ### Thread Pool
97
+ ```
98
+ $ puma -w 3 --preload
99
+ ```
65
100
 
66
- Puma utilizes a dynamic thread pool which you can modify. You can set the minimum and maximum number of threads that are available in the pool with the `-t` (or `--threads`) flag:
101
+ If you're using a configuration file, use the `preload_app!` method:
67
102
 
68
- $ puma -t 8:32
69
-
70
- Puma will automatically scale the number of threads based on how much traffic is present. The current default is `0:16`. Feel free to experiment, but be careful not to set the number of maximum threads to a very large number, as you may exhaust resources on the system (or hit resource limits).
103
+ ```ruby
104
+ # config/puma.rb
105
+ workers 3
106
+ preload_app!
107
+ ```
108
+
109
+ Additionally, you can specify a block in your configuration file that will be run on boot of each worker:
110
+
111
+ ```ruby
112
+ # config/puma.rb
113
+ on_worker_boot do
114
+ # configuration here
115
+ end
116
+ ```
117
+
118
+ This code can be used to setup the process before booting the application, allowing
119
+ you to do some Puma-specific things that you don't want to embed in your application.
120
+ For instance, you could fire a log notification that a worker booted or send something to statsd. This can be called multiple times.
121
+
122
+ `before_fork` specifies a block to be run before workers are forked:
123
+
124
+ ```ruby
125
+ # config/puma.rb
126
+ before_fork do
127
+ # configuration here
128
+ end
129
+ ```
130
+
131
+ Preloading can’t be used with phased restart, since phased restart kills and restarts workers one-by-one, and preload_app copies the code of master into the workers.
132
+
133
+ ### Error handling
134
+
135
+ If puma encounters an error outside of the context of your application, it will respond with a 500 and a simple
136
+ textual error message (see `lowlevel_error` in [this file](https://github.com/puma/puma/blob/master/lib/puma/server.rb)).
137
+ You can specify custom behavior for this scenario. For example, you can report the error to your third-party
138
+ error-tracking service (in this example, [rollbar](http://rollbar.com)):
139
+
140
+ ```ruby
141
+ lowlevel_error_handler do |e|
142
+ Rollbar.critical(e)
143
+ [500, {}, ["An error has occurred, and engineers have been informed. Please reload the page. If you continue to have problems, contact support@example.com\n"]]
144
+ end
145
+ ```
71
146
 
72
147
  ### Binding TCP / Sockets
73
148
 
74
- In contrast to many other server configs which require multiple flags, Puma simply uses one URI parameter with the `-b` (or `--bind`) flag:
149
+ Bind Puma to a socket with the `-b` (or `--bind`) flag:
75
150
 
76
- $ puma -b tcp://127.0.0.1:9292
151
+ ```
152
+ $ puma -b tcp://127.0.0.1:9292
153
+ ```
77
154
 
78
- Want to use UNIX Sockets instead of TCP (which can provide a 5-10% performance boost)? No problem!
155
+ To use a UNIX Socket instead of TCP:
79
156
 
80
- $ puma -b unix:///var/run/puma.sock
157
+ ```
158
+ $ puma -b unix:///var/run/puma.sock
159
+ ```
81
160
 
82
161
  If you need to change the permissions of the UNIX socket, just add a umask parameter:
83
162
 
84
- $ puma -b 'unix:///var/run/puma.sock?umask=0777'
163
+ ```
164
+ $ puma -b 'unix:///var/run/puma.sock?umask=0111'
165
+ ```
166
+
167
+ Need a bit of security? Use SSL sockets:
168
+
169
+ ```
170
+ $ puma -b 'ssl://127.0.0.1:9292?key=path_to_key&cert=path_to_cert'
171
+ ```
85
172
 
86
- Need a bit of security? Use SSL sockets!
173
+ #### Controlling SSL Cipher Suites
87
174
 
88
- $ puma -b 'ssl://127.0.0.1:9292?key=path_to_key&cert=path_to_cert'
175
+ To use or avoid specific SSL cipher suites, use `ssl_cipher_filter` or `ssl_cipher_list` options.
176
+
177
+ ##### Ruby:
178
+
179
+ ```
180
+ $ puma -b 'ssl://127.0.0.1:9292?key=path_to_key&cert=path_to_cert&ssl_cipher_filter=!aNULL:AES+SHA'
181
+ ```
182
+
183
+ ##### JRuby:
184
+
185
+ ```
186
+ $ puma -b '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'
187
+ ```
188
+
189
+ See https://www.openssl.org/docs/man1.0.2/apps/ciphers.html for cipher filter format and full list of cipher suites.
190
+
191
+ Disable TLS v1 with the `no_tlsv1` option:
192
+
193
+ ```
194
+ $ puma -b 'ssl://127.0.0.1:9292?key=path_to_key&cert=path_to_cert&no_tlsv1=true'
195
+ ```
89
196
 
90
197
  ### Control/Status Server
91
198
 
92
- Puma comes with a builtin status/control app that can be used query and control puma itself. Here is an example of starting puma with the control server:
199
+ Puma has a built-in status and control app that can be used to query and control Puma.
200
+
201
+ ```
202
+ $ puma --control-url tcp://127.0.0.1:9293 --control-token foo
203
+ ```
204
+
205
+ 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, `token=foo`) as a query parameter. This allows for simple authentication. Check out [status.rb](https://github.com/puma/puma/blob/master/lib/puma/app/status.rb) to see what the status app has available.
206
+
207
+ You can also interact with the control server via `pumactl`. This command will restart Puma:
208
+
209
+ ```
210
+ $ pumactl --control-url 'tcp://127.0.0.1:9293' --control-token foo restart
211
+ ```
212
+
213
+ To see a list of `pumactl` options, use `pumactl --help`.
93
214
 
94
- $ puma --control tcp://127.0.0.1:9293 --control-token foo
215
+ ### Configuration File
95
216
 
96
- This directs puma to start the control server on localhost port 9293. Additionally, all requests to the control server will need to include `token=foo` as a query parameter. This allows for simple authentication. Check out https://github.com/puma/puma/blob/master/lib/puma/app/status.rb to see what the app has available.
217
+ You can also provide a configuration file with the `-C` (or `--config`) flag:
218
+
219
+ ```
220
+ $ puma -C /path/to/config
221
+ ```
222
+
223
+ If no configuration file is specified, Puma will look for a configuration file at `config/puma.rb`. If an environment is specified, either via the `-e` and `--environment` flags, or through the `RACK_ENV` or the `RAILS_ENV` environment variables, Puma looks for configuration at `config/puma/<environment_name>.rb`.
224
+
225
+ If you want to prevent Puma from looking for a configuration file in those locations, provide a dash as the argument to the `-C` (or `--config`) flag:
226
+
227
+ ```
228
+ $ puma -C "-"
229
+ ```
230
+
231
+ The other side-effects of setting the environment are whether to show stack traces (in `development` or `test`), and setting RACK_ENV may potentially affect middleware looking for this value to change their behavior. The default puma RACK_ENV value is `development`. You can see all config default values [here](https://github.com/puma/puma/blob/12d1706ddc71b89ed2ee26275e31c788e94ff541/lib/puma/configuration.rb#L170).
232
+
233
+ Check out [dsl.rb](https://github.com/puma/puma/blob/master/lib/puma/dsl.rb) to see all available options.
97
234
 
98
235
  ## Restart
99
236
 
100
- Puma includes the ability to restart itself, allowing for new versions to be easily upgraded to. When available (currently anywhere but JRuby), puma performs a "hot restart". This is the same functionality available in *unicorn* and *nginx* which keep the server sockets open between restarts. This makes sure that no pending requests are dropped while the restart is taking place.
237
+ Puma includes the ability to restart itself. When available (MRI, Rubinius, JRuby), Puma performs a "hot restart". This is the same functionality available in *Unicorn* and *NGINX* which keep the server sockets open between restarts. This makes sure that no pending requests are dropped while the restart is taking place.
238
+
239
+ For more, see the [restart documentation](https://github.com/puma/puma/blob/master/docs/restart.md).
240
+
241
+ ## Signals
242
+
243
+ Puma responds to several signals. A detailed guide to using UNIX signals with Puma can be found in the [signals documentation](https://github.com/puma/puma/blob/master/docs/signals.md).
244
+
245
+ ## Platform Constraints
246
+
247
+ Some platforms do not support all Puma features.
101
248
 
102
- To perform a restart, there are 2 builtin mechanism:
249
+ * **JRuby**, **Windows**: 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).
250
+ * **Windows**: Cluster mode is not supported due to a lack of fork(2).
103
251
 
104
- * Send the puma process the `SIGUSR2` signal
105
- * Use the status server and issue `/restart`
252
+ ## Known Bugs
106
253
 
107
- No code is shared between the current and restarted process, so it should be safe to issue a restart any place where you would manually stop puma and start it again.
254
+ 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 ```stream closed in another thread (IOError)```. It may be caused by a [Ruby bug](https://bugs.ruby-lang.org/issues/13632). It can be fixed with the gem https://rubygems.org/gems/stopgap_13632:
108
255
 
109
- If the new process is unable to load, it will simply exit. You should therefore run puma under a supervisor when using it in production.
256
+ ```ruby
257
+ if %w(2.2.7 2.2.8 2.2.9 2.2.10 2.3.4 2.4.1).include? RUBY_VERSION
258
+ begin
259
+ require 'stopgap_13632'
260
+ rescue LoadError
261
+ end
262
+ end
263
+ ```
110
264
 
111
- ### Cleanup Code
265
+ ## Deployment
112
266
 
113
- Puma isn't able to understand all the resources that your app may use, so it provides a hook in the configuration file you pass to `-C` call `on_restart`. The block passed to `on_restart` will be called, unsurprisingly, just before puma restarts itself.
267
+ Puma has support for Capistrano with an [external gem](https://github.com/seuros/capistrano-puma).
114
268
 
115
- You should place code to close global log files, redis connections, etc in this block so that their file descriptors don't leak into the restarted process. Failure to do so will result in slowly running out of descriptors and eventually obscure crashes as the server is restart many times.
269
+ It is common to use process monitors with Puma. Modern process monitors like systemd or upstart
270
+ provide continuous monitoring and restarts for increased
271
+ reliability in production environments:
116
272
 
117
- ## pumactl
273
+ * [docs/jungle](https://github.com/puma/puma/tree/master/docs/jungle) for rc.d and upstart
274
+ * [docs/systemd](https://github.com/puma/puma/blob/master/docs/systemd.md)
118
275
 
119
- If you start puma with `-S some/path` then you can pass that same path to the `pumactl` program to control your server. For instance:
276
+ ## Community Extensions
120
277
 
121
- $ pumactl -S some/path command
278
+ ### Plugins
122
279
 
123
- or
280
+ * [puma-heroku](https://github.com/puma/puma-heroku) — default Puma configuration for running on Heroku
281
+ * [puma-metrics](https://github.com/harmjanblok/puma-metrics) — export Puma metrics to Prometheus
282
+ * [puma-plugin-statsd](https://github.com/yob/puma-plugin-statsd) — send Puma metrics to statsd
283
+ * [puma-plugin-systemd](https://github.com/sj26/puma-plugin-systemd) — deeper integration with systemd for notify, status and watchdog
124
284
 
125
- $ pumactl -C url -T token command
285
+ ### Monitoring
126
286
 
127
- will cause the server to perform a restart. `pumactl` is a simple CLI frontend to the control/status app described above.
287
+ * [puma-status](https://github.com/ylecuyer/puma-status) — Monitor CPU/Mem/Load of running puma instances from the CLI
128
288
 
129
- Allowed commands: status, restart, halt, stop
289
+ ## Contributing
130
290
 
131
- ## Managing multiple Pumas / init.d script
291
+ Find details for contributing in the [contribution guide].
132
292
 
133
- If you want an easy way to manage multiple scripts at once check [tools/jungle](https://github.com/puma/puma/tree/master/tools/jungle) for an init.d script.
293
+ [contribution guide]: https://github.com/puma/puma/blob/master/CONTRIBUTING.md
134
294
 
135
295
  ## License
136
296
 
137
- Puma is copyright 2011 Evan Phoenix and contributors. It is licensed under the BSD license. See the include LICENSE file for details.
297
+ Puma is copyright Evan Phoenix and contributors, licensed under the BSD 3-Clause license. See the included LICENSE file for details.
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Copyright (c) 2014 Evan Phoenix
4
+ #
5
+
6
+ require 'rubygems'
7
+
8
+ gems = ARGV.shift
9
+
10
+ inc = ""
11
+
12
+ if gems == "-I"
13
+ inc = ARGV.shift
14
+ $LOAD_PATH.concat inc.split(":")
15
+ gems = ARGV.shift
16
+ end
17
+
18
+ gems.split(",").each do |s|
19
+ name, ver = s.split(":",2)
20
+ gem name, ver
21
+ end
22
+
23
+ module Puma; end
24
+
25
+ Puma.const_set("WILD_ARGS", ["-I", inc, gems])
26
+
27
+ require 'puma/cli'
28
+
29
+ cli = Puma::CLI.new ARGV
30
+
31
+ cli.run
@@ -2,7 +2,7 @@
2
2
 
3
3
  require 'puma/control_cli'
4
4
 
5
- cli = Puma::ControlCLI.new ARGV
5
+ cli = Puma::ControlCLI.new ARGV.dup
6
6
 
7
7
  begin
8
8
  cli.run