puma-simon 3.7.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (157) hide show
  1. checksums.yaml +7 -0
  2. data/.github/issue_template.md +20 -0
  3. data/.gitignore +18 -0
  4. data/.hoeignore +12 -0
  5. data/.travis.yml +29 -0
  6. data/DEPLOYMENT.md +91 -0
  7. data/Gemfile +12 -0
  8. data/History.md +1254 -0
  9. data/LICENSE +26 -0
  10. data/Manifest.txt +78 -0
  11. data/README.md +353 -0
  12. data/Rakefile +158 -0
  13. data/Release.md +9 -0
  14. data/bin/puma +10 -0
  15. data/bin/puma-wild +31 -0
  16. data/bin/pumactl +12 -0
  17. data/docs/nginx.md +80 -0
  18. data/docs/signals.md +43 -0
  19. data/docs/systemd.md +197 -0
  20. data/examples/CA/cacert.pem +23 -0
  21. data/examples/CA/newcerts/cert_1.pem +19 -0
  22. data/examples/CA/newcerts/cert_2.pem +19 -0
  23. data/examples/CA/private/cakeypair.pem +30 -0
  24. data/examples/CA/serial +1 -0
  25. data/examples/config.rb +200 -0
  26. data/examples/plugins/redis_stop_puma.rb +46 -0
  27. data/examples/puma/cert_puma.pem +19 -0
  28. data/examples/puma/client-certs/ca.crt +19 -0
  29. data/examples/puma/client-certs/ca.key +27 -0
  30. data/examples/puma/client-certs/client.crt +19 -0
  31. data/examples/puma/client-certs/client.key +27 -0
  32. data/examples/puma/client-certs/client_expired.crt +19 -0
  33. data/examples/puma/client-certs/client_expired.key +27 -0
  34. data/examples/puma/client-certs/client_unknown.crt +19 -0
  35. data/examples/puma/client-certs/client_unknown.key +27 -0
  36. data/examples/puma/client-certs/generate.rb +78 -0
  37. data/examples/puma/client-certs/keystore.jks +0 -0
  38. data/examples/puma/client-certs/server.crt +19 -0
  39. data/examples/puma/client-certs/server.key +27 -0
  40. data/examples/puma/client-certs/server.p12 +0 -0
  41. data/examples/puma/client-certs/unknown_ca.crt +19 -0
  42. data/examples/puma/client-certs/unknown_ca.key +27 -0
  43. data/examples/puma/csr_puma.pem +11 -0
  44. data/examples/puma/keystore.jks +0 -0
  45. data/examples/puma/puma_keypair.pem +15 -0
  46. data/examples/qc_config.rb +13 -0
  47. data/ext/puma_http11/PumaHttp11Service.java +17 -0
  48. data/ext/puma_http11/ext_help.h +15 -0
  49. data/ext/puma_http11/extconf.rb +15 -0
  50. data/ext/puma_http11/http11_parser.c +1069 -0
  51. data/ext/puma_http11/http11_parser.h +65 -0
  52. data/ext/puma_http11/http11_parser.java.rl +161 -0
  53. data/ext/puma_http11/http11_parser.rl +147 -0
  54. data/ext/puma_http11/http11_parser_common.rl +54 -0
  55. data/ext/puma_http11/io_buffer.c +155 -0
  56. data/ext/puma_http11/mini_ssl.c +457 -0
  57. data/ext/puma_http11/org/jruby/puma/Http11.java +234 -0
  58. data/ext/puma_http11/org/jruby/puma/Http11Parser.java +473 -0
  59. data/ext/puma_http11/org/jruby/puma/MiniSSL.java +339 -0
  60. data/ext/puma_http11/puma_http11.c +500 -0
  61. data/gemfiles/2.1-Gemfile +12 -0
  62. data/lib/puma.rb +15 -0
  63. data/lib/puma/accept_nonblock.rb +23 -0
  64. data/lib/puma/app/status.rb +66 -0
  65. data/lib/puma/binder.rb +402 -0
  66. data/lib/puma/cli.rb +220 -0
  67. data/lib/puma/client.rb +434 -0
  68. data/lib/puma/cluster.rb +510 -0
  69. data/lib/puma/commonlogger.rb +106 -0
  70. data/lib/puma/compat.rb +14 -0
  71. data/lib/puma/configuration.rb +364 -0
  72. data/lib/puma/const.rb +224 -0
  73. data/lib/puma/control_cli.rb +259 -0
  74. data/lib/puma/convenient.rb +23 -0
  75. data/lib/puma/daemon_ext.rb +31 -0
  76. data/lib/puma/delegation.rb +11 -0
  77. data/lib/puma/detect.rb +13 -0
  78. data/lib/puma/dsl.rb +486 -0
  79. data/lib/puma/events.rb +152 -0
  80. data/lib/puma/io_buffer.rb +7 -0
  81. data/lib/puma/java_io_buffer.rb +45 -0
  82. data/lib/puma/jruby_restart.rb +83 -0
  83. data/lib/puma/launcher.rb +410 -0
  84. data/lib/puma/minissl.rb +221 -0
  85. data/lib/puma/null_io.rb +42 -0
  86. data/lib/puma/plugin.rb +115 -0
  87. data/lib/puma/plugin/tmp_restart.rb +35 -0
  88. data/lib/puma/rack/backports/uri/common_193.rb +33 -0
  89. data/lib/puma/rack/builder.rb +298 -0
  90. data/lib/puma/rack/urlmap.rb +91 -0
  91. data/lib/puma/rack_default.rb +7 -0
  92. data/lib/puma/reactor.rb +210 -0
  93. data/lib/puma/runner.rb +171 -0
  94. data/lib/puma/server.rb +949 -0
  95. data/lib/puma/single.rb +112 -0
  96. data/lib/puma/state_file.rb +29 -0
  97. data/lib/puma/tcp_logger.rb +39 -0
  98. data/lib/puma/thread_pool.rb +297 -0
  99. data/lib/puma/util.rb +128 -0
  100. data/lib/rack/handler/puma.rb +78 -0
  101. data/puma.gemspec +52 -0
  102. data/test/ab_rs.rb +22 -0
  103. data/test/config.rb +2 -0
  104. data/test/config/app.rb +9 -0
  105. data/test/config/plugin.rb +1 -0
  106. data/test/config/settings.rb +2 -0
  107. data/test/config/state_file_testing_config.rb +14 -0
  108. data/test/hello-bind.ru +2 -0
  109. data/test/hello-delay.ru +3 -0
  110. data/test/hello-map.ru +3 -0
  111. data/test/hello-post.ru +4 -0
  112. data/test/hello-stuck.ru +1 -0
  113. data/test/hello-tcp.ru +5 -0
  114. data/test/hello.ru +1 -0
  115. data/test/hijack.ru +6 -0
  116. data/test/hijack2.ru +5 -0
  117. data/test/lobster.ru +4 -0
  118. data/test/shell/run.sh +24 -0
  119. data/test/shell/t1.rb +19 -0
  120. data/test/shell/t1_conf.rb +3 -0
  121. data/test/shell/t2.rb +17 -0
  122. data/test/shell/t2_conf.rb +6 -0
  123. data/test/shell/t3.rb +25 -0
  124. data/test/shell/t3_conf.rb +5 -0
  125. data/test/slow.ru +4 -0
  126. data/test/ssl_config.rb +4 -0
  127. data/test/test_app_status.rb +93 -0
  128. data/test/test_binder.rb +31 -0
  129. data/test/test_cli.rb +209 -0
  130. data/test/test_config.rb +95 -0
  131. data/test/test_events.rb +161 -0
  132. data/test/test_helper.rb +50 -0
  133. data/test/test_http10.rb +27 -0
  134. data/test/test_http11.rb +186 -0
  135. data/test/test_integration.rb +247 -0
  136. data/test/test_iobuffer.rb +39 -0
  137. data/test/test_minissl.rb +29 -0
  138. data/test/test_null_io.rb +49 -0
  139. data/test/test_persistent.rb +245 -0
  140. data/test/test_puma_server.rb +626 -0
  141. data/test/test_puma_server_ssl.rb +222 -0
  142. data/test/test_rack_handler.rb +57 -0
  143. data/test/test_rack_server.rb +138 -0
  144. data/test/test_tcp_logger.rb +39 -0
  145. data/test/test_tcp_rack.rb +36 -0
  146. data/test/test_thread_pool.rb +250 -0
  147. data/test/test_unix_socket.rb +35 -0
  148. data/test/test_web_server.rb +88 -0
  149. data/tools/jungle/README.md +9 -0
  150. data/tools/jungle/init.d/README.md +59 -0
  151. data/tools/jungle/init.d/puma +421 -0
  152. data/tools/jungle/init.d/run-puma +18 -0
  153. data/tools/jungle/upstart/README.md +61 -0
  154. data/tools/jungle/upstart/puma-manager.conf +31 -0
  155. data/tools/jungle/upstart/puma.conf +69 -0
  156. data/tools/trickletest.rb +45 -0
  157. metadata +297 -0
data/LICENSE ADDED
@@ -0,0 +1,26 @@
1
+ Some code copyright (c) 2005, Zed Shaw
2
+ Copyright (c) 2011, Evan Phoenix
3
+ All rights reserved.
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions are met:
7
+
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.
16
+
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
26
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,78 @@
1
+ .github/issue_template.md
2
+ DEPLOYMENT.md
3
+ Gemfile
4
+ History.md
5
+ LICENSE
6
+ Manifest.txt
7
+ README.md
8
+ Rakefile
9
+ Release.md
10
+ bin/puma
11
+ bin/puma-wild
12
+ bin/pumactl
13
+ docs/nginx.md
14
+ docs/signals.md
15
+ docs/systemd.md
16
+ ext/puma_http11/PumaHttp11Service.java
17
+ ext/puma_http11/ext_help.h
18
+ ext/puma_http11/extconf.rb
19
+ ext/puma_http11/http11_parser.c
20
+ ext/puma_http11/http11_parser.h
21
+ ext/puma_http11/http11_parser.java.rl
22
+ ext/puma_http11/http11_parser.rl
23
+ ext/puma_http11/http11_parser_common.rl
24
+ ext/puma_http11/io_buffer.c
25
+ ext/puma_http11/mini_ssl.c
26
+ ext/puma_http11/org/jruby/puma/Http11.java
27
+ ext/puma_http11/org/jruby/puma/Http11Parser.java
28
+ ext/puma_http11/org/jruby/puma/MiniSSL.java
29
+ ext/puma_http11/puma_http11.c
30
+ gemfiles/2.1-Gemfile
31
+ lib/puma.rb
32
+ lib/puma/accept_nonblock.rb
33
+ lib/puma/app/status.rb
34
+ lib/puma/binder.rb
35
+ lib/puma/cli.rb
36
+ lib/puma/client.rb
37
+ lib/puma/cluster.rb
38
+ lib/puma/commonlogger.rb
39
+ lib/puma/compat.rb
40
+ lib/puma/configuration.rb
41
+ lib/puma/const.rb
42
+ lib/puma/control_cli.rb
43
+ lib/puma/convenient.rb
44
+ lib/puma/daemon_ext.rb
45
+ lib/puma/delegation.rb
46
+ lib/puma/detect.rb
47
+ lib/puma/dsl.rb
48
+ lib/puma/events.rb
49
+ lib/puma/io_buffer.rb
50
+ lib/puma/java_io_buffer.rb
51
+ lib/puma/jruby_restart.rb
52
+ lib/puma/launcher.rb
53
+ lib/puma/minissl.rb
54
+ lib/puma/null_io.rb
55
+ lib/puma/plugin.rb
56
+ lib/puma/plugin/tmp_restart.rb
57
+ lib/puma/rack/backports/uri/common_193.rb
58
+ lib/puma/rack/builder.rb
59
+ lib/puma/rack/urlmap.rb
60
+ lib/puma/rack_default.rb
61
+ lib/puma/reactor.rb
62
+ lib/puma/runner.rb
63
+ lib/puma/server.rb
64
+ lib/puma/single.rb
65
+ lib/puma/state_file.rb
66
+ lib/puma/tcp_logger.rb
67
+ lib/puma/thread_pool.rb
68
+ lib/puma/util.rb
69
+ lib/rack/handler/puma.rb
70
+ puma.gemspec
71
+ tools/jungle/README.md
72
+ tools/jungle/init.d/README.md
73
+ tools/jungle/init.d/puma
74
+ tools/jungle/init.d/run-puma
75
+ tools/jungle/upstart/README.md
76
+ tools/jungle/upstart/puma-manager.conf
77
+ tools/jungle/upstart/puma.conf
78
+ tools/trickletest.rb
@@ -0,0 +1,353 @@
1
+ # Puma: A Ruby Web Server Built For Concurrency
2
+
3
+ [![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/puma/puma?utm\_source=badge&utm\_medium=badge&utm\_campaign=pr-badge)
4
+ [![Build Status](https://secure.travis-ci.org/puma/puma.svg)](http://travis-ci.org/puma/puma)
5
+ [![Dependency Status](https://gemnasium.com/puma/puma.svg)](https://gemnasium.com/puma/puma)
6
+ [![Code Climate](https://codeclimate.com/github/puma/puma.svg)](https://codeclimate.com/github/puma/puma)
7
+
8
+ ## Description
9
+
10
+ Puma is a simple, fast, threaded, and highly concurrent HTTP 1.1 server for Ruby/Rack applications. Puma is intended for use in both development and production environments. In order to get the best throughput, it is highly recommended that you use a Ruby implementation with real threads like Rubinius or JRuby.
11
+
12
+ ## Built For Speed & Concurrency
13
+
14
+ 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
+
16
+ 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
+
18
+ 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
+
20
+ 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
+
22
+ ## Quick Start
23
+
24
+ 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
+
28
+ Now you should have the `puma` command available in your PATH, so just do the following in the root folder of your Rack application:
29
+
30
+ $ puma app.ru
31
+
32
+ ## Plugins
33
+
34
+ Puma 3.0 added support for plugins that can augment configuration and service operations.
35
+
36
+ 2 canonical plugins to look to aid in development of further plugins:
37
+
38
+ * [tmp\_restart](https://github.com/puma/puma/blob/master/lib/puma/plugin/tmp_restart.rb): Restarts the server if the file `tmp/restart.txt` is touched
39
+ * [heroku](https://github.com/puma/puma-heroku/blob/master/lib/puma/plugin/heroku.rb): Packages up the default configuration used by puma on Heroku
40
+
41
+ Plugins are activated in a puma configuration file (such as `config/puma.rb'`) by adding `plugin "name"`, such as `plugin "heroku"`.
42
+
43
+ Plugins are activated based simply on path requirements so, activating the `heroku` plugin will simply be doing `require "puma/plugin/heroku"`. This allows gems to provide multiple plugins (as well as unrelated gems to provide puma plugins).
44
+
45
+ The `tmp_restart` plugin is bundled with puma, so it can always be used.
46
+
47
+ To use the `heroku` plugin, add `puma-heroku` to your Gemfile or install it.
48
+
49
+ ### API
50
+
51
+ At present, there are 2 hooks that plugins can use: `start` and `config`.
52
+
53
+ `start` runs when the server has started and allows the plugin to start other functionality to augment puma.
54
+
55
+ `config` runs when the server is being configured and is passed a `Puma::DSL` object that can be used to add additional configuration.
56
+
57
+ Any public methods in `Puma::Plugin` are the public API that any plugin may use.
58
+
59
+ In the future, more hooks and APIs will be added.
60
+
61
+
62
+ ## Advanced Setup
63
+
64
+ ### Sinatra
65
+
66
+ You can run your Sinatra application with Puma from the command line like this:
67
+
68
+ $ ruby app.rb -s Puma
69
+
70
+ Or you can configure your application to always use Puma:
71
+
72
+ require 'sinatra'
73
+ configure { set :server, :puma }
74
+
75
+ If you use Bundler, make sure you add Puma to your Gemfile (see below).
76
+
77
+ ### Rails
78
+
79
+ First, make sure Puma is in your Gemfile:
80
+
81
+ gem 'puma'
82
+
83
+ Then start your server with the `rails` command:
84
+
85
+ $ rails s Puma
86
+
87
+ ### Rackup
88
+
89
+ You can pass it as an option to `rackup`:
90
+
91
+ $ rackup -s Puma
92
+
93
+ Alternatively, you can modify your `config.ru` to choose Puma by default, by adding the following as the first line:
94
+
95
+ #\ -s puma
96
+
97
+ ## Configuration
98
+
99
+ Puma provides numerous options for controlling the operation of the server. Consult `puma -h` (or `puma --help`) for a full list.
100
+
101
+ ### Thread Pool
102
+
103
+ 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:
104
+
105
+ $ puma -t 8:32
106
+
107
+ 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`. 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).
108
+
109
+ ### Clustered mode
110
+
111
+ Puma 2 offers clustered mode, allowing you to use forked processes to handle multiple incoming requests concurrently, in addition to threads already provided. You can tune the number of workers with the `-w` (or `--workers`) flag:
112
+
113
+ $ puma -t 8:32 -w 3
114
+
115
+ On a ruby implementation that offers native threads, you should tune this number to match the number of cores available.
116
+ 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 be 32 threads.
117
+
118
+ If you're running in Clustered Mode you can optionally choose to preload your application before starting up the workers. This is necessary in order to take advantage of the [Copy on Write](http://en.wikipedia.org/wiki/Copy-on-write) feature introduced in [MRI Ruby 2.0](https://blog.heroku.com/archives/2013/3/6/matz_highlights_ruby_2_0_at_waza). To do this simply specify the `--preload` flag in invocation:
119
+
120
+ # CLI invocation
121
+ $ puma -t 8:32 -w 3 --preload
122
+
123
+ If you're using a configuration file, use the `preload_app!` method, and be sure to specify your config file's location with the `-C` flag:
124
+
125
+ $ puma -C config/puma.rb
126
+
127
+ # config/puma.rb
128
+ threads 8,32
129
+ workers 3
130
+ preload_app!
131
+
132
+ Additionally, you can specify a block in your configuration file that will be run on boot of each worker:
133
+
134
+ # config/puma.rb
135
+ on_worker_boot do
136
+ # configuration here
137
+ end
138
+
139
+ This code can be used to setup the process before booting the application, allowing
140
+ you to do some Puma-specific things that you don't want to embed in your application.
141
+ For instance, you could fire a log notification that a worker booted or send something to statsd.
142
+ This can be called multiple times to add hooks.
143
+
144
+ If you're preloading your application and using ActiveRecord, it's recommended that you setup your connection pool here:
145
+
146
+ # config/puma.rb
147
+ on_worker_boot do
148
+ ActiveSupport.on_load(:active_record) do
149
+ ActiveRecord::Base.establish_connection
150
+ end
151
+ end
152
+
153
+ On top of that, you can specify a block in your configuration file that will be run before workers are forked
154
+
155
+ # config/puma.rb
156
+ before_fork do
157
+ # configuration here
158
+ end
159
+
160
+ This code can be used to clean up before forking to clients, allowing
161
+ you to do some Puma-specific things that you don't want to embed in your application.
162
+
163
+ If you're preloading your application and using ActiveRecord, it's recommended that you close any connections to the database here to prevent connection leakage:
164
+
165
+ # config/puma.rb
166
+ before_fork do
167
+ ActiveRecord::Base.connection_pool.disconnect!
168
+ end
169
+
170
+ This rule applies to any connections to external services (Redis, databases, memcache, ...) that might be started automatically by the framework.
171
+
172
+ When you use preload_app, all of your new code goes into the master process, and is then copied into the workers (meaning it’s only compatible with cluster mode). General rule is to use preload_app when your workers die often and need fast starts. If you don’t have many workers, you probably should not use preload_app.
173
+
174
+ Note that preload_app can’t be used with phased restart, since phased restart kills and restarts workers one-by-one, and preload_app is all about copying the code of master into the workers.
175
+
176
+ ### Error handler for low-level errors
177
+
178
+ If puma encounters an error outside of the context of your application, it will respond with a 500 and a simple
179
+ textual error message (see `lowlevel_error` in [this file](https://github.com/puma/puma/blob/master/lib/puma/server.rb)).
180
+ You can specify custom behavior for this scenario. For example, you can report the error to your third-party
181
+ error-tracking service (in this example, [rollbar](http://rollbar.com)):
182
+
183
+ ```ruby
184
+ lowlevel_error_handler do |e|
185
+ Rollbar.critical(e)
186
+ [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"]]
187
+ end
188
+ ```
189
+
190
+ ### Binding TCP / Sockets
191
+
192
+ In contrast to many other server configs which require multiple flags, Puma simply uses one URI parameter with the `-b` (or `--bind`) flag:
193
+
194
+ $ puma -b tcp://127.0.0.1:9292
195
+
196
+ Want to use UNIX Sockets instead of TCP (which can provide a 5-10% performance boost)? No problem!
197
+
198
+ $ puma -b unix:///var/run/puma.sock
199
+
200
+ If you need to change the permissions of the UNIX socket, just add a umask parameter:
201
+
202
+ $ puma -b 'unix:///var/run/puma.sock?umask=0111'
203
+
204
+ Need a bit of security? Use SSL sockets!
205
+
206
+ $ puma -b 'ssl://127.0.0.1:9292?key=path_to_key&cert=path_to_cert'
207
+
208
+ ### Control/Status Server
209
+
210
+ Puma comes with a builtin status/control app that can be used to query and control Puma itself. Here is an example of starting Puma with the control server:
211
+
212
+ $ puma --control tcp://127.0.0.1:9293 --control-token foo
213
+
214
+ 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 [status.rb](https://github.com/puma/puma/blob/master/lib/puma/app/status.rb) to see what the app has available.
215
+
216
+ Keep in mind that the status/control server accepts `pumactl` commands. To demonstrate, you can run the following command with the foo `--control-token` as such to restart:
217
+
218
+ $ pumactl restart --control-token foo
219
+
220
+ To see a list of `pumactl` options, please see `pumactl --help` as stated in the [`pumactl`](https://github.com/puma/puma#pumactl) section.
221
+
222
+ ### Configuration file
223
+
224
+ You can also provide a configuration file which Puma will use with the `-C` (or `--config`) flag:
225
+
226
+ $ puma -C /path/to/config
227
+
228
+ By default, 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` environment variable, the default file location will be config/puma/environment_name.rb.
229
+
230
+ 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:
231
+
232
+ $ puma -C "-"
233
+
234
+ Take the following [sample configuration](https://github.com/puma/puma/blob/master/examples/config.rb) as inspiration or check out [configuration.rb](https://github.com/puma/puma/blob/master/lib/puma/configuration.rb) to see all available options.
235
+
236
+ ## Restart
237
+
238
+ Puma includes the ability to restart itself allowing easy upgrades to new versions. 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.
239
+
240
+ To perform a restart, there are 2 builtin mechanisms:
241
+
242
+ * Send the `puma` process the `SIGUSR2` signal
243
+ * Use the status server and issue `/restart`
244
+
245
+ 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.
246
+
247
+ If the new process is unable to load, it will simply exit. You should therefore run Puma under a process monitor (see below) when using it in production.
248
+
249
+ ### Normal vs Hot vs Phased Restart
250
+
251
+ A hot restart means that no requests will be lost while deploying your new code, since the server socket is kept open between restarts.
252
+
253
+ But beware, hot restart does not mean that the incoming requests won’t hang for multiple seconds while your new code has not fully deployed. If you need a zero downtime and zero hanging requests deploy, you must use phased restart.
254
+
255
+ When you run pumactl phased-restart, Puma kills workers one-by-one, meaning that at least another worker is still available to serve requests, which lead to zero hanging requests (yay!).
256
+
257
+ But again beware, upgrading an application sometimes involves upgrading the database schema. With phased restart, there may be a moment during the deployment where processes belonging to the previous version and processes belonging to the new version both exist at the same time. Any database schema upgrades you perform must therefore be backwards-compatible with the old application version.
258
+
259
+ If you perform a lot of database migrations, you probably should not use phased restart and use a normal/hot restart instead (pumactl restart). That way, no code is shared while deploying (in that case, preload_app might help for quicker deployment, see below).
260
+
261
+ ### Puma Signals
262
+
263
+ Puma cluster responds to these signals:
264
+
265
+ - `TTIN` increment the worker count by 1
266
+ - `TTOU` decrement the worker count by 1
267
+ - `TERM` send `TERM` to worker. Worker will attempt to finish then exit.
268
+ - `USR2` restart workers
269
+ - `USR1` restart workers in phases, a rolling restart.
270
+ - `HUP` reopen log files defined in stdout_redirect configuration parameter
271
+ - `INT` equivalent of sending Ctrl-C to cluster. Will attempt to finish then exit.
272
+ - `CHLD`
273
+
274
+ 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).
275
+
276
+ ### Release Directory
277
+
278
+ If your symlink releases into a common working directory (i.e., `/current` from Capistrano), Puma won't pick up your new changes when running phased restarts without additional configuration. You should set your working directory within Puma's config to specify the directory it should use. This is a change from earlier versions of Puma (< 2.15) that would infer the directory for you.
279
+
280
+ ```ruby
281
+ # config/puma.rb
282
+
283
+ directory '/var/www/current'
284
+ ```
285
+
286
+ ### Cleanup Code
287
+
288
+ 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` called `on_restart`. The block passed to `on_restart` will be called, unsurprisingly, just before Puma restarts itself.
289
+
290
+ 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 restarted many times.
291
+
292
+ ### Platform Constraints
293
+
294
+ Because of various platforms not being able to implement certain things, the following differences occur when Puma is used on different platforms:
295
+
296
+ * **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
297
+ * **JRuby**, **Windows**: cluster mode is not supported due to a lack of fork(2)
298
+ * **Windows**: daemon mode is not supported due to a lack of fork(2)
299
+
300
+ ## pumactl
301
+
302
+ `pumactl` is a simple CLI frontend to the control/status app described above. Please refer to `pumactl --help` for available commands.
303
+
304
+ ## Process Monitors
305
+
306
+ Process monitors or supervisors will at minimum provide start of Puma
307
+ on system boot. Modern process monitors like systemd or upstart
308
+ further provide continuous monitoring and restarts for increased
309
+ reliability in production environments:
310
+
311
+ * [tools/jungle](https://github.com/puma/puma/tree/master/tools/jungle) for sysvinit (init.d) and upstart
312
+ * [docs/systemd](https://github.com/puma/puma/blob/master/docs/systemd.md)
313
+
314
+ ## Capistrano deployment
315
+
316
+ Puma has support for Capistrano3 with an [external gem](https://github.com/seuros/capistrano-puma), you just need require that in Gemfile:
317
+
318
+ ```ruby
319
+ gem 'capistrano3-puma'
320
+ ```
321
+ And then execute:
322
+
323
+ ```bash
324
+ bundle
325
+ ```
326
+
327
+ Then add to Capfile
328
+
329
+ ```ruby
330
+ require 'capistrano/puma'
331
+ ```
332
+
333
+ and then
334
+
335
+ ```bash
336
+ $ bundle exec cap puma:start
337
+ $ bundle exec cap puma:restart
338
+ $ bundle exec cap puma:stop
339
+ $ bundle exec cap puma:phased-restart
340
+ ```
341
+
342
+ ## Contributing
343
+
344
+ To run the test suite:
345
+
346
+ ```bash
347
+ $ bundle install
348
+ $ bundle exec rake
349
+ ```
350
+
351
+ ## License
352
+
353
+ Puma is copyright 2014 Evan Phoenix and contributors. It is licensed under the BSD 3-Clause license. See the included LICENSE file for details.