puma 4.3.12 → 6.3.1
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.
- checksums.yaml +4 -4
- data/History.md +1729 -521
- data/LICENSE +23 -20
- data/README.md +169 -45
- data/bin/puma-wild +3 -9
- data/docs/architecture.md +63 -26
- data/docs/compile_options.md +55 -0
- data/docs/deployment.md +60 -69
- data/docs/fork_worker.md +31 -0
- data/docs/images/puma-connection-flow-no-reactor.png +0 -0
- data/docs/images/puma-connection-flow.png +0 -0
- data/docs/images/puma-general-arch.png +0 -0
- data/docs/jungle/README.md +9 -0
- data/{tools → docs}/jungle/rc.d/README.md +1 -1
- data/{tools → docs}/jungle/rc.d/puma +2 -2
- data/{tools → docs}/jungle/rc.d/puma.conf +0 -0
- data/docs/kubernetes.md +66 -0
- data/docs/nginx.md +2 -2
- data/docs/plugins.md +15 -15
- data/docs/rails_dev_mode.md +28 -0
- data/docs/restart.md +46 -23
- data/docs/signals.md +13 -11
- data/docs/stats.md +142 -0
- data/docs/systemd.md +84 -128
- data/docs/testing_benchmarks_local_files.md +150 -0
- data/docs/testing_test_rackup_ci_files.md +36 -0
- data/ext/puma_http11/PumaHttp11Service.java +2 -4
- data/ext/puma_http11/ext_help.h +1 -1
- data/ext/puma_http11/extconf.rb +49 -12
- data/ext/puma_http11/http11_parser.c +46 -48
- data/ext/puma_http11/http11_parser.h +2 -2
- data/ext/puma_http11/http11_parser.java.rl +3 -3
- data/ext/puma_http11/http11_parser.rl +3 -3
- data/ext/puma_http11/http11_parser_common.rl +2 -2
- data/ext/puma_http11/mini_ssl.c +278 -93
- data/ext/puma_http11/no_ssl/PumaHttp11Service.java +15 -0
- data/ext/puma_http11/org/jruby/puma/Http11.java +6 -6
- data/ext/puma_http11/org/jruby/puma/Http11Parser.java +4 -6
- data/ext/puma_http11/org/jruby/puma/MiniSSL.java +241 -96
- data/ext/puma_http11/puma_http11.c +46 -57
- data/lib/puma/app/status.rb +53 -39
- data/lib/puma/binder.rb +237 -121
- data/lib/puma/cli.rb +34 -34
- data/lib/puma/client.rb +172 -98
- data/lib/puma/cluster/worker.rb +180 -0
- data/lib/puma/cluster/worker_handle.rb +97 -0
- data/lib/puma/cluster.rb +226 -231
- data/lib/puma/commonlogger.rb +21 -14
- data/lib/puma/configuration.rb +114 -87
- data/lib/puma/const.rb +139 -95
- data/lib/puma/control_cli.rb +99 -79
- data/lib/puma/detect.rb +33 -2
- data/lib/puma/dsl.rb +516 -110
- data/lib/puma/error_logger.rb +113 -0
- data/lib/puma/events.rb +16 -115
- data/lib/puma/io_buffer.rb +44 -2
- data/lib/puma/jruby_restart.rb +2 -59
- data/lib/puma/json_serialization.rb +96 -0
- data/lib/puma/launcher/bundle_pruner.rb +104 -0
- data/lib/puma/launcher.rb +164 -155
- data/lib/puma/log_writer.rb +147 -0
- data/lib/puma/minissl/context_builder.rb +36 -19
- data/lib/puma/minissl.rb +230 -55
- data/lib/puma/null_io.rb +18 -1
- data/lib/puma/plugin/systemd.rb +90 -0
- data/lib/puma/plugin/tmp_restart.rb +1 -1
- data/lib/puma/plugin.rb +3 -12
- data/lib/puma/rack/builder.rb +7 -11
- data/lib/puma/rack/urlmap.rb +0 -0
- data/lib/puma/rack_default.rb +19 -4
- data/lib/puma/reactor.rb +93 -368
- data/lib/puma/request.rb +671 -0
- data/lib/puma/runner.rb +92 -75
- data/lib/puma/sd_notify.rb +149 -0
- data/lib/puma/server.rb +321 -794
- data/lib/puma/single.rb +20 -74
- data/lib/puma/state_file.rb +45 -8
- data/lib/puma/thread_pool.rb +140 -68
- data/lib/puma/util.rb +21 -4
- data/lib/puma.rb +54 -7
- data/lib/rack/handler/puma.rb +113 -87
- data/tools/{docker/Dockerfile → Dockerfile} +1 -1
- data/tools/trickletest.rb +0 -0
- metadata +33 -24
- data/docs/tcp_mode.md +0 -96
- data/ext/puma_http11/io_buffer.c +0 -155
- data/ext/puma_http11/org/jruby/puma/IOBuffer.java +0 -72
- data/lib/puma/accept_nonblock.rb +0 -29
- data/lib/puma/tcp_logger.rb +0 -41
- data/tools/jungle/README.md +0 -19
- data/tools/jungle/init.d/README.md +0 -61
- data/tools/jungle/init.d/puma +0 -421
- data/tools/jungle/init.d/run-puma +0 -18
- data/tools/jungle/upstart/README.md +0 -61
- data/tools/jungle/upstart/puma-manager.conf +0 -31
- data/tools/jungle/upstart/puma.conf +0 -69
data/ext/puma_http11/io_buffer.c
DELETED
@@ -1,155 +0,0 @@
|
|
1
|
-
#define RSTRING_NOT_MODIFIED 1
|
2
|
-
#include "ruby.h"
|
3
|
-
|
4
|
-
#include <sys/types.h>
|
5
|
-
|
6
|
-
struct buf_int {
|
7
|
-
uint8_t* top;
|
8
|
-
uint8_t* cur;
|
9
|
-
|
10
|
-
size_t size;
|
11
|
-
};
|
12
|
-
|
13
|
-
#define BUF_DEFAULT_SIZE 4096
|
14
|
-
#define BUF_TOLERANCE 32
|
15
|
-
|
16
|
-
static void buf_free(struct buf_int* internal) {
|
17
|
-
xfree(internal->top);
|
18
|
-
xfree(internal);
|
19
|
-
}
|
20
|
-
|
21
|
-
static VALUE buf_alloc(VALUE self) {
|
22
|
-
VALUE buf;
|
23
|
-
struct buf_int* internal;
|
24
|
-
|
25
|
-
buf = Data_Make_Struct(self, struct buf_int, 0, buf_free, internal);
|
26
|
-
|
27
|
-
internal->size = BUF_DEFAULT_SIZE;
|
28
|
-
internal->top = ALLOC_N(uint8_t, BUF_DEFAULT_SIZE);
|
29
|
-
internal->cur = internal->top;
|
30
|
-
|
31
|
-
return buf;
|
32
|
-
}
|
33
|
-
|
34
|
-
static VALUE buf_append(VALUE self, VALUE str) {
|
35
|
-
struct buf_int* b;
|
36
|
-
size_t used, str_len, new_size;
|
37
|
-
|
38
|
-
Data_Get_Struct(self, struct buf_int, b);
|
39
|
-
|
40
|
-
used = b->cur - b->top;
|
41
|
-
|
42
|
-
StringValue(str);
|
43
|
-
str_len = RSTRING_LEN(str);
|
44
|
-
|
45
|
-
new_size = used + str_len;
|
46
|
-
|
47
|
-
if(new_size > b->size) {
|
48
|
-
size_t n = b->size + (b->size / 2);
|
49
|
-
uint8_t* top;
|
50
|
-
uint8_t* old;
|
51
|
-
|
52
|
-
new_size = (n > new_size ? n : new_size + BUF_TOLERANCE);
|
53
|
-
|
54
|
-
top = ALLOC_N(uint8_t, new_size);
|
55
|
-
old = b->top;
|
56
|
-
memcpy(top, old, used);
|
57
|
-
b->top = top;
|
58
|
-
b->cur = top + used;
|
59
|
-
b->size = new_size;
|
60
|
-
xfree(old);
|
61
|
-
}
|
62
|
-
|
63
|
-
memcpy(b->cur, RSTRING_PTR(str), str_len);
|
64
|
-
b->cur += str_len;
|
65
|
-
|
66
|
-
return self;
|
67
|
-
}
|
68
|
-
|
69
|
-
static VALUE buf_append2(int argc, VALUE* argv, VALUE self) {
|
70
|
-
struct buf_int* b;
|
71
|
-
size_t used, new_size;
|
72
|
-
int i;
|
73
|
-
VALUE str;
|
74
|
-
|
75
|
-
Data_Get_Struct(self, struct buf_int, b);
|
76
|
-
|
77
|
-
used = b->cur - b->top;
|
78
|
-
new_size = used;
|
79
|
-
|
80
|
-
for(i = 0; i < argc; i++) {
|
81
|
-
StringValue(argv[i]);
|
82
|
-
|
83
|
-
str = argv[i];
|
84
|
-
|
85
|
-
new_size += RSTRING_LEN(str);
|
86
|
-
}
|
87
|
-
|
88
|
-
if(new_size > b->size) {
|
89
|
-
size_t n = b->size + (b->size / 2);
|
90
|
-
uint8_t* top;
|
91
|
-
uint8_t* old;
|
92
|
-
|
93
|
-
new_size = (n > new_size ? n : new_size + BUF_TOLERANCE);
|
94
|
-
|
95
|
-
top = ALLOC_N(uint8_t, new_size);
|
96
|
-
old = b->top;
|
97
|
-
memcpy(top, old, used);
|
98
|
-
b->top = top;
|
99
|
-
b->cur = top + used;
|
100
|
-
b->size = new_size;
|
101
|
-
xfree(old);
|
102
|
-
}
|
103
|
-
|
104
|
-
for(i = 0; i < argc; i++) {
|
105
|
-
long str_len;
|
106
|
-
str = argv[i];
|
107
|
-
str_len = RSTRING_LEN(str);
|
108
|
-
memcpy(b->cur, RSTRING_PTR(str), str_len);
|
109
|
-
b->cur += str_len;
|
110
|
-
}
|
111
|
-
|
112
|
-
return self;
|
113
|
-
}
|
114
|
-
|
115
|
-
static VALUE buf_to_str(VALUE self) {
|
116
|
-
struct buf_int* b;
|
117
|
-
Data_Get_Struct(self, struct buf_int, b);
|
118
|
-
|
119
|
-
return rb_str_new((const char*)(b->top), b->cur - b->top);
|
120
|
-
}
|
121
|
-
|
122
|
-
static VALUE buf_used(VALUE self) {
|
123
|
-
struct buf_int* b;
|
124
|
-
Data_Get_Struct(self, struct buf_int, b);
|
125
|
-
|
126
|
-
return INT2FIX(b->cur - b->top);
|
127
|
-
}
|
128
|
-
|
129
|
-
static VALUE buf_capa(VALUE self) {
|
130
|
-
struct buf_int* b;
|
131
|
-
Data_Get_Struct(self, struct buf_int, b);
|
132
|
-
|
133
|
-
return INT2FIX(b->size);
|
134
|
-
}
|
135
|
-
|
136
|
-
static VALUE buf_reset(VALUE self) {
|
137
|
-
struct buf_int* b;
|
138
|
-
Data_Get_Struct(self, struct buf_int, b);
|
139
|
-
|
140
|
-
b->cur = b->top;
|
141
|
-
return self;
|
142
|
-
}
|
143
|
-
|
144
|
-
void Init_io_buffer(VALUE puma) {
|
145
|
-
VALUE buf = rb_define_class_under(puma, "IOBuffer", rb_cObject);
|
146
|
-
|
147
|
-
rb_define_alloc_func(buf, buf_alloc);
|
148
|
-
rb_define_method(buf, "<<", buf_append, 1);
|
149
|
-
rb_define_method(buf, "append", buf_append2, -1);
|
150
|
-
rb_define_method(buf, "to_str", buf_to_str, 0);
|
151
|
-
rb_define_method(buf, "to_s", buf_to_str, 0);
|
152
|
-
rb_define_method(buf, "used", buf_used, 0);
|
153
|
-
rb_define_method(buf, "capacity", buf_capa, 0);
|
154
|
-
rb_define_method(buf, "reset", buf_reset, 0);
|
155
|
-
}
|
@@ -1,72 +0,0 @@
|
|
1
|
-
package org.jruby.puma;
|
2
|
-
|
3
|
-
import org.jruby.*;
|
4
|
-
import org.jruby.anno.JRubyMethod;
|
5
|
-
import org.jruby.runtime.ObjectAllocator;
|
6
|
-
import org.jruby.runtime.ThreadContext;
|
7
|
-
import org.jruby.runtime.builtin.IRubyObject;
|
8
|
-
import org.jruby.util.ByteList;
|
9
|
-
|
10
|
-
/**
|
11
|
-
* @author kares
|
12
|
-
*/
|
13
|
-
public class IOBuffer extends RubyObject {
|
14
|
-
|
15
|
-
private static final ObjectAllocator ALLOCATOR = new ObjectAllocator() {
|
16
|
-
public IRubyObject allocate(Ruby runtime, RubyClass klass) {
|
17
|
-
return new IOBuffer(runtime, klass);
|
18
|
-
}
|
19
|
-
};
|
20
|
-
|
21
|
-
public static void createIOBuffer(Ruby runtime) {
|
22
|
-
RubyModule mPuma = runtime.defineModule("Puma");
|
23
|
-
RubyClass cIOBuffer = mPuma.defineClassUnder("IOBuffer", runtime.getObject(), ALLOCATOR);
|
24
|
-
cIOBuffer.defineAnnotatedMethods(IOBuffer.class);
|
25
|
-
}
|
26
|
-
|
27
|
-
private static final int DEFAULT_SIZE = 4096;
|
28
|
-
|
29
|
-
final ByteList buffer = new ByteList(DEFAULT_SIZE);
|
30
|
-
|
31
|
-
IOBuffer(Ruby runtime, RubyClass klass) {
|
32
|
-
super(runtime, klass);
|
33
|
-
}
|
34
|
-
|
35
|
-
@JRubyMethod
|
36
|
-
public RubyInteger used(ThreadContext context) {
|
37
|
-
return context.runtime.newFixnum(buffer.getRealSize());
|
38
|
-
}
|
39
|
-
|
40
|
-
@JRubyMethod
|
41
|
-
public RubyInteger capacity(ThreadContext context) {
|
42
|
-
return context.runtime.newFixnum(buffer.unsafeBytes().length);
|
43
|
-
}
|
44
|
-
|
45
|
-
@JRubyMethod
|
46
|
-
public IRubyObject reset() {
|
47
|
-
buffer.setRealSize(0);
|
48
|
-
return this;
|
49
|
-
}
|
50
|
-
|
51
|
-
@JRubyMethod(name = { "to_s", "to_str" })
|
52
|
-
public RubyString to_s(ThreadContext context) {
|
53
|
-
return RubyString.newStringShared(context.runtime, buffer.unsafeBytes(), 0, buffer.getRealSize());
|
54
|
-
}
|
55
|
-
|
56
|
-
@JRubyMethod(name = "<<")
|
57
|
-
public IRubyObject add(IRubyObject str) {
|
58
|
-
addImpl(str.convertToString());
|
59
|
-
return this;
|
60
|
-
}
|
61
|
-
|
62
|
-
@JRubyMethod(rest = true)
|
63
|
-
public IRubyObject append(IRubyObject[] strs) {
|
64
|
-
for (IRubyObject str : strs) addImpl(str.convertToString());
|
65
|
-
return this;
|
66
|
-
}
|
67
|
-
|
68
|
-
private void addImpl(RubyString str) {
|
69
|
-
buffer.append(str.getByteList());
|
70
|
-
}
|
71
|
-
|
72
|
-
}
|
data/lib/puma/accept_nonblock.rb
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'openssl'
|
4
|
-
|
5
|
-
module OpenSSL
|
6
|
-
module SSL
|
7
|
-
class SSLServer
|
8
|
-
unless public_method_defined? :accept_nonblock
|
9
|
-
def accept_nonblock
|
10
|
-
sock = @svr.accept_nonblock
|
11
|
-
|
12
|
-
begin
|
13
|
-
ssl = OpenSSL::SSL::SSLSocket.new(sock, @ctx)
|
14
|
-
ssl.sync_close = true
|
15
|
-
ssl.accept if @start_immediately
|
16
|
-
ssl
|
17
|
-
rescue SSLError => ex
|
18
|
-
if ssl
|
19
|
-
ssl.close
|
20
|
-
else
|
21
|
-
sock.close
|
22
|
-
end
|
23
|
-
raise ex
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
data/lib/puma/tcp_logger.rb
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Puma
|
4
|
-
class TCPLogger
|
5
|
-
def initialize(logger, app, quiet=false)
|
6
|
-
@logger = logger
|
7
|
-
@app = app
|
8
|
-
@quiet = quiet
|
9
|
-
end
|
10
|
-
|
11
|
-
FORMAT = "%s - %s"
|
12
|
-
|
13
|
-
def log(who, str)
|
14
|
-
now = Time.now.strftime("%d/%b/%Y %H:%M:%S")
|
15
|
-
|
16
|
-
log_str = "#{now} - #{who} - #{str}"
|
17
|
-
|
18
|
-
case @logger
|
19
|
-
when IO
|
20
|
-
@logger.puts log_str
|
21
|
-
when Events
|
22
|
-
@logger.log log_str
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
def call(env, socket)
|
27
|
-
who = env[Const::REMOTE_ADDR]
|
28
|
-
log who, "connected" unless @quiet
|
29
|
-
|
30
|
-
env['log'] = lambda { |str| log(who, str) }
|
31
|
-
|
32
|
-
begin
|
33
|
-
@app.call env, socket
|
34
|
-
rescue Object => e
|
35
|
-
log who, "exception: #{e.message} (#{e.class})"
|
36
|
-
else
|
37
|
-
log who, "disconnected" unless @quiet
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
data/tools/jungle/README.md
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
# Puma as a service
|
2
|
-
|
3
|
-
## Upstart
|
4
|
-
|
5
|
-
See `/tools/jungle/upstart` for Ubuntu's upstart scripts.
|
6
|
-
|
7
|
-
## Systemd
|
8
|
-
|
9
|
-
See [/docs/systemd](https://github.com/puma/puma/blob/master/docs/systemd.md).
|
10
|
-
|
11
|
-
## Init.d
|
12
|
-
|
13
|
-
Deprecatation Warning : `init.d` was replaced by `systemd` since Debian 8 and Ubuntu 16.04, you should look into [/docs/systemd](https://github.com/puma/puma/blob/master/docs/systemd.md) unless you are on an older OS.
|
14
|
-
|
15
|
-
See `/tools/jungle/init.d` for tools to use with init.d and start-stop-daemon.
|
16
|
-
|
17
|
-
## rc.d
|
18
|
-
|
19
|
-
See `/tools/jungle/rc.d` for FreeBSD's rc.d scripts
|
@@ -1,61 +0,0 @@
|
|
1
|
-
# Puma daemon service
|
2
|
-
|
3
|
-
Deprecatation Warning : `init.d` was replaced by `systemd` since Debian 8 and Ubuntu 16.04, you should look into [/docs/systemd](https://github.com/puma/puma/blob/master/docs/systemd.md) unless you are on an older OS.
|
4
|
-
|
5
|
-
Init script to manage multiple Puma servers on the same box using start-stop-daemon.
|
6
|
-
|
7
|
-
## Installation
|
8
|
-
|
9
|
-
# Copy the init script to services directory
|
10
|
-
sudo cp puma /etc/init.d
|
11
|
-
sudo chmod +x /etc/init.d/puma
|
12
|
-
|
13
|
-
# Make it start at boot time.
|
14
|
-
sudo update-rc.d -f puma defaults
|
15
|
-
|
16
|
-
# Copy the Puma runner to an accessible location
|
17
|
-
sudo cp run-puma /usr/local/bin
|
18
|
-
sudo chmod +x /usr/local/bin/run-puma
|
19
|
-
|
20
|
-
# Create an empty configuration file
|
21
|
-
sudo touch /etc/puma.conf
|
22
|
-
|
23
|
-
## Managing the jungle
|
24
|
-
|
25
|
-
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:
|
26
|
-
|
27
|
-
app-path,user,config-file-path,log-file-path,environment-variables
|
28
|
-
|
29
|
-
You can add an instance by editing the file or running the following command:
|
30
|
-
|
31
|
-
sudo /etc/init.d/puma add /path/to/app user /path/to/app/config/puma.rb /path/to/app/log/puma.log
|
32
|
-
|
33
|
-
The config and log paths, as well as the environment variables, are optional parameters and default to:
|
34
|
-
|
35
|
-
* config: /path/to/app/*config/puma.rb*
|
36
|
-
* log: /path/to/app/*log/puma.log*
|
37
|
-
* environment: (empty)
|
38
|
-
|
39
|
-
Multiple environment variables need to be separated by a semicolon, e.g.
|
40
|
-
|
41
|
-
FOO=1;BAR=2
|
42
|
-
|
43
|
-
To remove an app, simply delete the line from the config file or run:
|
44
|
-
|
45
|
-
sudo /etc/init.d/puma remove /path/to/app
|
46
|
-
|
47
|
-
The command will make sure the Puma instance stops before removing it from the jungle.
|
48
|
-
|
49
|
-
## Assumptions
|
50
|
-
|
51
|
-
* The script expects a temporary folder named /path/to/app/*tmp/puma* to exist. Create it if it's not there by default.
|
52
|
-
The pid and state files should live there and must be called: *tmp/puma/pid* and *tmp/puma/state*.
|
53
|
-
You can change those if you want but you'll have to adapt the script for it to work.
|
54
|
-
|
55
|
-
* Here's what a minimal app's config file should have:
|
56
|
-
|
57
|
-
```
|
58
|
-
pidfile "/path/to/app/tmp/puma/pid"
|
59
|
-
state_path "/path/to/app/tmp/puma/state"
|
60
|
-
activate_control_app
|
61
|
-
```
|