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
@@ -1,89 +0,0 @@
1
- # Copyright (c) 2011 Evan Phoenix
2
- # Copyright (c) 2005 Zed A. Shaw
3
-
4
- require 'test/testhelp'
5
-
6
- include Puma
7
-
8
- class TestHandler
9
- attr_reader :ran_test
10
-
11
- def call(env)
12
- @ran_test = true
13
-
14
- [200, {"Content-Type" => "text/plain"}, ["hello!"]]
15
- end
16
- end
17
-
18
- class WebServerTest < Test::Unit::TestCase
19
-
20
- def setup
21
- @valid_request = "GET / HTTP/1.1\r\nHost: www.zedshaw.com\r\nContent-Type: text/plain\r\n\r\n"
22
-
23
- @tester = TestHandler.new
24
-
25
- @server = Server.new @tester, Events.strings
26
- @server.add_tcp_listener "127.0.0.1", 9998
27
-
28
- @server.run
29
- end
30
-
31
- def teardown
32
- @server.stop(true)
33
- end
34
-
35
- def test_simple_server
36
- hit(['http://127.0.0.1:9998/test'])
37
- assert @tester.ran_test, "Handler didn't really run"
38
- end
39
-
40
-
41
- def do_test(string, chunk, close_after=nil, shutdown_delay=0)
42
- # Do not use instance variables here, because it needs to be thread safe
43
- socket = TCPSocket.new("127.0.0.1", 9998);
44
- request = StringIO.new(string)
45
- chunks_out = 0
46
-
47
- while data = request.read(chunk)
48
- chunks_out += socket.write(data)
49
- socket.flush
50
- sleep 0.2
51
- if close_after and chunks_out > close_after
52
- socket.close
53
- sleep 1
54
- end
55
- end
56
- sleep(shutdown_delay)
57
- socket.write(" ") # Some platforms only raise the exception on attempted write
58
- socket.flush
59
- end
60
-
61
- def test_trickle_attack
62
- do_test(@valid_request, 3)
63
- end
64
-
65
- def test_close_client
66
- assert_raises IOError do
67
- do_test(@valid_request, 10, 20)
68
- end
69
- end
70
-
71
- def test_bad_client
72
- do_test("GET /test HTTP/BAD", 3)
73
- end
74
-
75
- def test_header_is_too_long
76
- long = "GET /test HTTP/1.1\r\n" + ("X-Big: stuff\r\n" * 15000) + "\r\n"
77
- assert_raises Errno::ECONNRESET, Errno::EPIPE, Errno::ECONNABORTED, Errno::EINVAL, IOError do
78
- do_test(long, long.length/2, 10)
79
- end
80
- end
81
-
82
- def test_file_streamed_request
83
- body = "a" * (Puma::Const::MAX_BODY * 2)
84
- long = "GET /test HTTP/1.1\r\nContent-length: #{body.length}\r\n\r\n" + body
85
- do_test(long, (Puma::Const::CHUNK_SIZE * 2) - 400)
86
- end
87
-
88
- end
89
-
@@ -1,54 +0,0 @@
1
- # Puma daemon service
2
-
3
- Init script to manage multiple Puma servers on the same box using start-stop-daemon.
4
-
5
- ## Installation
6
-
7
- # Copy the init script to services directory
8
- sudo cp puma /etc/init.d
9
- sudo chmod +x /etc/init.d/puma
10
-
11
- # Make it start at boot time.
12
- sudo update-rc.d -f puma defaults
13
-
14
- # Copy the Puma runner to an accessible location
15
- sudo cp run-puma /usr/local/bin
16
- sudo chmod +x /usr/local/bin/run-puma
17
-
18
- # Create an empty configuration file
19
- sudo touch /etc/puma.conf
20
-
21
- ## Managing the jungle
22
-
23
- Puma apps are held in /etc/puma.conf by default. It's mainly a CSV file and every line represents one app. Here's the syntax:
24
-
25
- app-path,user,config-file-path,log-file-path
26
-
27
- You can add an instance by editing the file or running the following command:
28
-
29
- sudo /etc/init.d/puma add /path/to/app user /path/to/app/config/puma.rb /path/to/app/config/log/puma.log
30
-
31
- The config and log paths are optional parameters and default to:
32
-
33
- * config: /path/to/app/*config/puma.rb*
34
- * log: /path/to/app/*config/puma.log*
35
-
36
- To remove an app, simply delete the line from the config file or run:
37
-
38
- sudo /etc/init.d/puma remove /path/to/app
39
-
40
- The command will make sure the Puma instance stops before removing it from the jungle.
41
-
42
- ## Assumptions
43
-
44
- * The script expects a temporary folder named /path/to/app/*tmp/puma* to exist. Create it if it's not there by default.
45
- The pid and state files should live there and must be called: *tmp/puma/pid* and *tmp/puma/state*.
46
- You can change those if you want but you'll have to adapt the script for it to work.
47
-
48
- * Here's what a minimal app's config file should have:
49
-
50
- ```
51
- pidfile "/path/to/app/tmp/puma/pid"
52
- state_path "/path/to/app/tmp/puma/state"
53
- activate_control_app
54
- ```
@@ -1,332 +0,0 @@
1
- #! /bin/sh
2
- ### BEGIN INIT INFO
3
- # Provides: puma
4
- # Required-Start: $remote_fs $syslog
5
- # Required-Stop: $remote_fs $syslog
6
- # Default-Start: 2 3 4 5
7
- # Default-Stop: 0 1 6
8
- # Short-Description: Example initscript
9
- # Description: This file should be used to construct scripts to be
10
- # placed in /etc/init.d.
11
- ### END INIT INFO
12
-
13
- # Author: Darío Javier Cravero <dario@exordo.com>
14
- #
15
- # Do NOT "set -e"
16
-
17
- # PATH should only include /usr/* if it runs after the mountnfs.sh script
18
- PATH=/usr/local/bin:/usr/local/sbin/:/sbin:/usr/sbin:/bin:/usr/bin
19
- DESC="Puma rack web server"
20
- NAME=puma
21
- DAEMON=$NAME
22
- SCRIPTNAME=/etc/init.d/$NAME
23
- CONFIG=/etc/puma.conf
24
- JUNGLE=`cat $CONFIG`
25
- RUNPUMA=/usr/local/bin/run-puma
26
-
27
- # Load the VERBOSE setting and other rcS variables
28
- . /lib/init/vars.sh
29
-
30
- # Define LSB log_* functions.
31
- # Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
32
- . /lib/lsb/init-functions
33
-
34
- #
35
- # Function that starts the jungle
36
- #
37
- do_start() {
38
- log_daemon_msg "=> Running the jungle..."
39
- for i in $JUNGLE; do
40
- dir=`echo $i | cut -d , -f 1`
41
- user=`echo $i | cut -d , -f 2`
42
- config_file=`echo $i | cut -d , -f 3`
43
- if [ "$config_file" = "" ]; then
44
- config_file="$dir/config/puma.rb"
45
- fi
46
- log_file=`echo $i | cut -d , -f 4`
47
- if [ "$log_file" = "" ]; then
48
- log_file="$dir/log/puma.log"
49
- fi
50
- do_start_one $dir $user $config_file $log_file
51
- done
52
- }
53
-
54
- do_start_one() {
55
- PIDFILE=$1/tmp/puma/pid
56
- if [ -e $PIDFILE ]; then
57
- PID=`cat $PIDFILE`
58
- # If the puma isn't running, run it, otherwise restart it.
59
- if [ "`ps -A -o pid= | grep -c $PID`" -eq 0 ]; then
60
- do_start_one_do $1 $2 $3 $4
61
- else
62
- do_restart_one $1
63
- fi
64
- else
65
- do_start_one_do $1 $2 $3 $4
66
- fi
67
- }
68
-
69
- do_start_one_do() {
70
- log_daemon_msg "--> Woke up puma $1"
71
- log_daemon_msg "user $2"
72
- log_daemon_msg "log to $4"
73
- start-stop-daemon --verbose --start --chdir $1 --chuid $2 --background --exec $RUNPUMA -- $1 $3 $4
74
- }
75
-
76
- #
77
- # Function that stops the jungle
78
- #
79
- do_stop() {
80
- log_daemon_msg "=> Putting all the beasts to bed..."
81
- for i in $JUNGLE; do
82
- dir=`echo $i | cut -d , -f 1`
83
- do_stop_one $dir
84
- done
85
- }
86
- #
87
- # Function that stops the daemon/service
88
- #
89
- do_stop_one() {
90
- log_daemon_msg "--> Stopping $1"
91
- PIDFILE=$1/tmp/puma/pid
92
- STATEFILE=$1/tmp/puma/state
93
- if [ -e $PIDFILE ]; then
94
- PID=`cat $PIDFILE`
95
- if [ "`ps -A -o pid= | grep -c $PID`" -eq 0 ]; then
96
- log_daemon_msg "---> Puma $1 isn't running."
97
- else
98
- log_daemon_msg "---> About to kill PID `cat $PIDFILE`"
99
- pumactl --state $STATEFILE stop
100
- # Many daemons don't delete their pidfiles when they exit.
101
- rm -f $PIDFILE $STATEFILE
102
- fi
103
- else
104
- log_daemon_msg "---> No puma here..."
105
- fi
106
- return 0
107
- }
108
-
109
- #
110
- # Function that restarts the jungle
111
- #
112
- do_restart() {
113
- for i in $JUNGLE; do
114
- dir=`echo $i | cut -d , -f 1`
115
- do_restart_one $dir
116
- done
117
- }
118
-
119
- #
120
- # Function that sends a SIGUSR2 to the daemon/service
121
- #
122
- do_restart_one() {
123
- PIDFILE=$1/tmp/puma/pid
124
- i=`grep $1 $CONFIG`
125
- dir=`echo $i | cut -d , -f 1`
126
-
127
- if [ -e $PIDFILE ]; then
128
- log_daemon_msg "--> About to restart puma $1"
129
- pumactl --state $dir/tmp/puma/state restart
130
- # kill -s USR2 `cat $PIDFILE`
131
- # TODO Check if process exist
132
- else
133
- log_daemon_msg "--> Your puma was never playing... Let's get it out there first"
134
- user=`echo $i | cut -d , -f 2`
135
- config_file=`echo $i | cut -d , -f 3`
136
- if [ "$config_file" = "" ]; then
137
- config_file="$dir/config/puma.rb"
138
- fi
139
- log_file=`echo $i | cut -d , -f 4`
140
- if [ "$log_file" = "" ]; then
141
- log_file="$dir/log/puma.log"
142
- fi
143
- do_start_one $dir $user $config_file $log_file
144
- fi
145
- return 0
146
- }
147
-
148
- #
149
- # Function that statuss the jungle
150
- #
151
- do_status() {
152
- for i in $JUNGLE; do
153
- dir=`echo $i | cut -d , -f 1`
154
- do_status_one $dir
155
- done
156
- }
157
-
158
- #
159
- # Function that sends a SIGUSR2 to the daemon/service
160
- #
161
- do_status_one() {
162
- PIDFILE=$1/tmp/puma/pid
163
- i=`grep $1 $CONFIG`
164
- dir=`echo $i | cut -d , -f 1`
165
-
166
- if [ -e $PIDFILE ]; then
167
- log_daemon_msg "--> About to status puma $1"
168
- pumactl --state $dir/tmp/puma/state stats
169
- # kill -s USR2 `cat $PIDFILE`
170
- # TODO Check if process exist
171
- else
172
- log_daemon_msg "--> $1 isn't there :(..."
173
- fi
174
- return 0
175
- }
176
-
177
- do_add() {
178
- str=""
179
- # App's directory
180
- if [ -d "$1" ]; then
181
- if [ "`grep -c "^$1" $CONFIG`" -eq 0 ]; then
182
- str=$1
183
- else
184
- echo "The app is already being managed. Remove it if you want to update its config."
185
- exit 1
186
- fi
187
- else
188
- echo "The directory $1 doesn't exist."
189
- exit 1
190
- fi
191
- # User to run it as
192
- if [ "`grep -c "^$2:" /etc/passwd`" -eq 0 ]; then
193
- echo "The user $2 doesn't exist."
194
- exit 1
195
- else
196
- str="$str,$2"
197
- fi
198
- # Config file
199
- if [ "$3" != "" ]; then
200
- if [ -e $3 ]; then
201
- str="$str,$3"
202
- else
203
- echo "The config file $3 doesn't exist."
204
- exit 1
205
- fi
206
- fi
207
- # Log file
208
- if [ "$4" != "" ]; then
209
- str="$str,$4"
210
- fi
211
-
212
- # Add it to the jungle
213
- echo $str >> $CONFIG
214
- log_daemon_msg "Added a Puma to the jungle: $str. You still have to start it though."
215
- }
216
-
217
- do_remove() {
218
- if [ "`grep -c "^$1" $CONFIG`" -eq 0 ]; then
219
- echo "There's no app $1 to remove."
220
- else
221
- # Stop it first.
222
- do_stop_one $1
223
- # Remove it from the config.
224
- sed -i "\\:^$1:d" $CONFIG
225
- log_daemon_msg "Removed a Puma from the jungle: $1."
226
- fi
227
- }
228
-
229
- case "$1" in
230
- start)
231
- [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
232
- if [ "$#" -eq 1 ]; then
233
- do_start
234
- else
235
- i=`grep $2 $CONFIG`
236
- dir=`echo $i | cut -d , -f 1`
237
- user=`echo $i | cut -d , -f 2`
238
- config_file=`echo $i | cut -d , -f 3`
239
- if [ "$config_file" = "" ]; then
240
- config_file="$dir/config/puma.rb"
241
- fi
242
- log_file=`echo $i | cut -d , -f 4`
243
- if [ "$log_file" = "" ]; then
244
- log_file="$dir/log/puma.log"
245
- fi
246
- do_start_one $dir $user $config_file $log_file
247
- fi
248
- case "$?" in
249
- 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
250
- 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
251
- esac
252
- ;;
253
- stop)
254
- [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
255
- if [ "$#" -eq 1 ]; then
256
- do_stop
257
- else
258
- i=`grep $2 $CONFIG`
259
- dir=`echo $i | cut -d , -f 1`
260
- do_stop_one $dir
261
- fi
262
- case "$?" in
263
- 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
264
- 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
265
- esac
266
- ;;
267
- status)
268
- # TODO Implement.
269
- log_daemon_msg "Status $DESC" "$NAME"
270
- if [ "$#" -eq 1 ]; then
271
- do_status
272
- else
273
- i=`grep $2 $CONFIG`
274
- dir=`echo $i | cut -d , -f 1`
275
- do_status_one $dir
276
- fi
277
- case "$?" in
278
- 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
279
- 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
280
- esac
281
- ;;
282
- restart)
283
- log_daemon_msg "Restarting $DESC" "$NAME"
284
- if [ "$#" -eq 1 ]; then
285
- do_restart
286
- else
287
- i=`grep $2 $CONFIG`
288
- dir=`echo $i | cut -d , -f 1`
289
- do_restart_one $dir
290
- fi
291
- case "$?" in
292
- 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
293
- 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
294
- esac
295
- ;;
296
- add)
297
- if [ "$#" -lt 3 ]; then
298
- echo "Please, specifiy the app's directory and the user that will run it at least."
299
- echo " Usage: $SCRIPTNAME add /path/to/app user /path/to/app/config/puma.rb /path/to/app/config/log/puma.log"
300
- echo " config and log are optionals."
301
- exit 1
302
- else
303
- do_add $2 $3 $4 $5
304
- fi
305
- case "$?" in
306
- 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
307
- 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
308
- esac
309
- ;;
310
- remove)
311
- if [ "$#" -lt 2 ]; then
312
- echo "Please, specifiy the app's directory to remove."
313
- exit 1
314
- else
315
- do_remove $2
316
- fi
317
- case "$?" in
318
- 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
319
- 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
320
- esac
321
- ;;
322
- *)
323
- echo "Usage:" >&2
324
- echo " Run the jungle: $SCRIPTNAME {start|stop|status|restart}" >&2
325
- echo " Add a Puma: $SCRIPTNAME add /path/to/app user /path/to/app/config/puma.rb /path/to/app/config/log/puma.log"
326
- echo " config and log are optionals."
327
- echo " Remove a Puma: $SCRIPTNAME remove /path/to/app"
328
- echo " On a Puma: $SCRIPTNAME {start|stop|status|restart} PUMA-NAME" >&2
329
- exit 3
330
- ;;
331
- esac
332
- :