puma 3.0.0.rc1 → 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.
- checksums.yaml +5 -5
- data/{History.txt → History.md} +703 -70
- data/LICENSE +23 -20
- data/README.md +173 -163
- data/docs/architecture.md +37 -0
- data/{DEPLOYMENT.md → docs/deployment.md} +28 -6
- 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 +13 -0
- data/docs/jungle/rc.d/README.md +74 -0
- data/docs/jungle/rc.d/puma +61 -0
- data/docs/jungle/rc.d/puma.conf +10 -0
- data/{tools → docs}/jungle/upstart/README.md +0 -0
- data/{tools → docs}/jungle/upstart/puma-manager.conf +0 -0
- data/{tools → docs}/jungle/upstart/puma.conf +1 -1
- data/docs/nginx.md +2 -2
- data/docs/plugins.md +38 -0
- data/docs/restart.md +41 -0
- data/docs/signals.md +57 -3
- data/docs/systemd.md +228 -0
- data/ext/puma_http11/PumaHttp11Service.java +2 -2
- data/ext/puma_http11/extconf.rb +16 -0
- data/ext/puma_http11/http11_parser.c +287 -468
- data/ext/puma_http11/http11_parser.h +1 -0
- data/ext/puma_http11/http11_parser.java.rl +21 -37
- data/ext/puma_http11/http11_parser.rl +10 -9
- data/ext/puma_http11/http11_parser_common.rl +4 -4
- data/ext/puma_http11/mini_ssl.c +159 -10
- data/ext/puma_http11/org/jruby/puma/Http11.java +108 -116
- data/ext/puma_http11/org/jruby/puma/Http11Parser.java +99 -132
- data/ext/puma_http11/org/jruby/puma/MiniSSL.java +30 -6
- data/ext/puma_http11/puma_http11.c +6 -38
- data/lib/puma.rb +25 -5
- data/lib/puma/accept_nonblock.rb +7 -1
- data/lib/puma/app/status.rb +53 -26
- data/lib/puma/binder.rb +150 -119
- data/lib/puma/cli.rb +56 -38
- data/lib/puma/client.rb +277 -80
- data/lib/puma/cluster.rb +326 -130
- data/lib/puma/commonlogger.rb +21 -20
- data/lib/puma/configuration.rb +160 -161
- data/lib/puma/const.rb +50 -47
- data/lib/puma/control_cli.rb +104 -63
- data/lib/puma/detect.rb +13 -1
- data/lib/puma/dsl.rb +463 -114
- data/lib/puma/events.rb +22 -13
- data/lib/puma/io_buffer.rb +9 -5
- data/lib/puma/jruby_restart.rb +2 -59
- data/lib/puma/launcher.rb +195 -105
- data/lib/puma/minissl.rb +110 -4
- data/lib/puma/minissl/context_builder.rb +76 -0
- data/lib/puma/null_io.rb +9 -14
- data/lib/puma/plugin.rb +32 -12
- data/lib/puma/plugin/tmp_restart.rb +19 -6
- data/lib/puma/rack/builder.rb +7 -5
- data/lib/puma/rack/urlmap.rb +11 -8
- data/lib/puma/rack_default.rb +2 -0
- data/lib/puma/reactor.rb +242 -32
- data/lib/puma/runner.rb +41 -30
- data/lib/puma/server.rb +265 -183
- data/lib/puma/single.rb +22 -63
- data/lib/puma/state_file.rb +9 -2
- data/lib/puma/thread_pool.rb +179 -68
- data/lib/puma/util.rb +3 -11
- data/lib/rack/handler/puma.rb +60 -11
- data/tools/Dockerfile +16 -0
- data/tools/trickletest.rb +1 -2
- metadata +35 -99
- data/COPYING +0 -55
- data/Gemfile +0 -13
- data/Manifest.txt +0 -79
- data/Rakefile +0 -158
- data/docs/config.md +0 -0
- data/ext/puma_http11/io_buffer.c +0 -155
- data/lib/puma/capistrano.rb +0 -94
- data/lib/puma/compat.rb +0 -18
- data/lib/puma/convenient.rb +0 -23
- data/lib/puma/daemon_ext.rb +0 -31
- data/lib/puma/delegation.rb +0 -11
- data/lib/puma/java_io_buffer.rb +0 -45
- data/lib/puma/rack/backports/uri/common_18.rb +0 -56
- data/lib/puma/rack/backports/uri/common_192.rb +0 -52
- data/lib/puma/rack/backports/uri/common_193.rb +0 -29
- data/lib/puma/tcp_logger.rb +0 -32
- data/puma.gemspec +0 -52
- data/tools/jungle/README.md +0 -9
- data/tools/jungle/init.d/README.md +0 -54
- data/tools/jungle/init.d/puma +0 -394
- data/tools/jungle/init.d/run-puma +0 -3
data/Manifest.txt
DELETED
@@ -1,79 +0,0 @@
|
|
1
|
-
COPYING
|
2
|
-
DEPLOYMENT.md
|
3
|
-
Gemfile
|
4
|
-
History.txt
|
5
|
-
LICENSE
|
6
|
-
Manifest.txt
|
7
|
-
README.md
|
8
|
-
Rakefile
|
9
|
-
bin/puma
|
10
|
-
bin/puma-wild
|
11
|
-
bin/pumactl
|
12
|
-
docs/config.md
|
13
|
-
docs/nginx.md
|
14
|
-
docs/signals.md
|
15
|
-
ext/puma_http11/PumaHttp11Service.java
|
16
|
-
ext/puma_http11/ext_help.h
|
17
|
-
ext/puma_http11/extconf.rb
|
18
|
-
ext/puma_http11/http11_parser.c
|
19
|
-
ext/puma_http11/http11_parser.h
|
20
|
-
ext/puma_http11/http11_parser.java.rl
|
21
|
-
ext/puma_http11/http11_parser.rl
|
22
|
-
ext/puma_http11/http11_parser_common.rl
|
23
|
-
ext/puma_http11/io_buffer.c
|
24
|
-
ext/puma_http11/mini_ssl.c
|
25
|
-
ext/puma_http11/org/jruby/puma/Http11.java
|
26
|
-
ext/puma_http11/org/jruby/puma/Http11Parser.java
|
27
|
-
ext/puma_http11/org/jruby/puma/MiniSSL.java
|
28
|
-
ext/puma_http11/puma_http11.c
|
29
|
-
lib/puma.rb
|
30
|
-
lib/puma/accept_nonblock.rb
|
31
|
-
lib/puma/app/status.rb
|
32
|
-
lib/puma/binder.rb
|
33
|
-
lib/puma/capistrano.rb
|
34
|
-
lib/puma/cli.rb
|
35
|
-
lib/puma/client.rb
|
36
|
-
lib/puma/cluster.rb
|
37
|
-
lib/puma/commonlogger.rb
|
38
|
-
lib/puma/compat.rb
|
39
|
-
lib/puma/configuration.rb
|
40
|
-
lib/puma/const.rb
|
41
|
-
lib/puma/control_cli.rb
|
42
|
-
lib/puma/convenient.rb
|
43
|
-
lib/puma/daemon_ext.rb
|
44
|
-
lib/puma/delegation.rb
|
45
|
-
lib/puma/detect.rb
|
46
|
-
lib/puma/dsl.rb
|
47
|
-
lib/puma/events.rb
|
48
|
-
lib/puma/io_buffer.rb
|
49
|
-
lib/puma/java_io_buffer.rb
|
50
|
-
lib/puma/jruby_restart.rb
|
51
|
-
lib/puma/launcher.rb
|
52
|
-
lib/puma/minissl.rb
|
53
|
-
lib/puma/null_io.rb
|
54
|
-
lib/puma/plugin.rb
|
55
|
-
lib/puma/plugin/tmp_restart.rb
|
56
|
-
lib/puma/rack/backports/uri/common_18.rb
|
57
|
-
lib/puma/rack/backports/uri/common_192.rb
|
58
|
-
lib/puma/rack/backports/uri/common_193.rb
|
59
|
-
lib/puma/rack/builder.rb
|
60
|
-
lib/puma/rack/urlmap.rb
|
61
|
-
lib/puma/rack_default.rb
|
62
|
-
lib/puma/reactor.rb
|
63
|
-
lib/puma/runner.rb
|
64
|
-
lib/puma/server.rb
|
65
|
-
lib/puma/single.rb
|
66
|
-
lib/puma/state_file.rb
|
67
|
-
lib/puma/tcp_logger.rb
|
68
|
-
lib/puma/thread_pool.rb
|
69
|
-
lib/puma/util.rb
|
70
|
-
lib/rack/handler/puma.rb
|
71
|
-
puma.gemspec
|
72
|
-
tools/jungle/README.md
|
73
|
-
tools/jungle/init.d/README.md
|
74
|
-
tools/jungle/init.d/puma
|
75
|
-
tools/jungle/init.d/run-puma
|
76
|
-
tools/jungle/upstart/README.md
|
77
|
-
tools/jungle/upstart/puma-manager.conf
|
78
|
-
tools/jungle/upstart/puma.conf
|
79
|
-
tools/trickletest.rb
|
data/Rakefile
DELETED
@@ -1,158 +0,0 @@
|
|
1
|
-
require "hoe"
|
2
|
-
require "rake/extensiontask"
|
3
|
-
require "rake/javaextensiontask"
|
4
|
-
|
5
|
-
IS_JRUBY = defined?(RUBY_ENGINE) ? RUBY_ENGINE == "jruby" : false
|
6
|
-
|
7
|
-
Hoe.plugin :git
|
8
|
-
Hoe.plugin :ignore
|
9
|
-
|
10
|
-
HOE = Hoe.spec "puma" do
|
11
|
-
self.readme_file = "README.md"
|
12
|
-
self.urls = %w!http://puma.io https://github.com/puma/puma!
|
13
|
-
|
14
|
-
license "BSD-3-Clause"
|
15
|
-
developer 'Evan Phoenix', 'evan@phx.io'
|
16
|
-
|
17
|
-
spec_extras[:extensions] = ["ext/puma_http11/extconf.rb"]
|
18
|
-
spec_extras[:executables] = ['puma', 'pumactl']
|
19
|
-
spec_extras[:homepage] = self.urls.first
|
20
|
-
|
21
|
-
require_ruby_version ">= 1.8.7"
|
22
|
-
|
23
|
-
dependency "rack", [">= 1.1", "< 2.0"], :development
|
24
|
-
|
25
|
-
extra_dev_deps << ["rake-compiler", "~> 0.8"]
|
26
|
-
end
|
27
|
-
|
28
|
-
task :prerelease => [:clobber, :check_manifest, :test]
|
29
|
-
|
30
|
-
# hoe/test and rake-compiler don't seem to play well together, so disable
|
31
|
-
# hoe/test's .gemtest touch file thingy for now
|
32
|
-
HOE.spec.files -= [".gemtest"]
|
33
|
-
|
34
|
-
include Hoe::Git
|
35
|
-
|
36
|
-
desc "Print the current changelog."
|
37
|
-
task "changelog" do
|
38
|
-
tag = ENV["FROM"] || git_tags.last
|
39
|
-
range = [tag, "HEAD"].compact.join ".."
|
40
|
-
cmd = "git log #{range} '--format=tformat:%B|||%aN|||%aE|||'"
|
41
|
-
now = Time.new.strftime "%Y-%m-%d"
|
42
|
-
|
43
|
-
changes = `#{cmd}`.split(/\|\|\|/).each_slice(3).map { |msg, author, email|
|
44
|
-
msg.split(/\n/).reject { |s| s.empty? }.first
|
45
|
-
}.flatten.compact
|
46
|
-
|
47
|
-
$changes = Hash.new { |h,k| h[k] = [] }
|
48
|
-
|
49
|
-
codes = {
|
50
|
-
"!" => :major,
|
51
|
-
"+" => :minor,
|
52
|
-
"*" => :minor,
|
53
|
-
"-" => :bug,
|
54
|
-
"?" => :unknown,
|
55
|
-
}
|
56
|
-
|
57
|
-
codes_re = Regexp.escape codes.keys.join
|
58
|
-
|
59
|
-
changes.each do |change|
|
60
|
-
if change =~ /^\s*([#{codes_re}])\s*(.*)/ then
|
61
|
-
code, line = codes[$1], $2
|
62
|
-
else
|
63
|
-
code, line = codes["?"], change.chomp
|
64
|
-
end
|
65
|
-
|
66
|
-
$changes[code] << line
|
67
|
-
end
|
68
|
-
|
69
|
-
puts "=== #{ENV['VERSION'] || 'NEXT'} / #{now}"
|
70
|
-
puts
|
71
|
-
changelog_section :major
|
72
|
-
changelog_section :minor
|
73
|
-
changelog_section :bug
|
74
|
-
changelog_section :unknown
|
75
|
-
puts
|
76
|
-
end
|
77
|
-
|
78
|
-
# generate extension code using Ragel (C and Java)
|
79
|
-
desc "Generate extension code (C and Java) using Ragel"
|
80
|
-
task :ragel
|
81
|
-
|
82
|
-
file 'ext/puma_http11/http11_parser.c' => ['ext/puma_http11/http11_parser.rl'] do |t|
|
83
|
-
begin
|
84
|
-
sh "ragel #{t.prerequisites.last} -C -G2 -I ext/puma_http11 -o #{t.name}"
|
85
|
-
rescue
|
86
|
-
fail "Could not build wrapper using Ragel (it failed or not installed?)"
|
87
|
-
end
|
88
|
-
end
|
89
|
-
task :ragel => ['ext/puma_http11/http11_parser.c']
|
90
|
-
|
91
|
-
file 'ext/puma_http11/org/jruby/puma/Http11Parser.java' => ['ext/puma_http11/http11_parser.java.rl'] do |t|
|
92
|
-
begin
|
93
|
-
sh "ragel #{t.prerequisites.last} -J -G2 -I ext/puma_http11 -o #{t.name}"
|
94
|
-
rescue
|
95
|
-
fail "Could not build wrapper using Ragel (it failed or not installed?)"
|
96
|
-
end
|
97
|
-
end
|
98
|
-
task :ragel => ['ext/puma_http11/org/jruby/puma/Http11Parser.java']
|
99
|
-
|
100
|
-
if !IS_JRUBY
|
101
|
-
|
102
|
-
# compile extensions using rake-compiler
|
103
|
-
# C (MRI, Rubinius)
|
104
|
-
Rake::ExtensionTask.new("puma_http11", HOE.spec) do |ext|
|
105
|
-
# place extension inside namespace
|
106
|
-
ext.lib_dir = "lib/puma"
|
107
|
-
|
108
|
-
ext.cross_compile = true
|
109
|
-
ext.cross_platform = ['i386-mswin32-60', 'i386-mingw32']
|
110
|
-
ext.cross_compiling do |spec|
|
111
|
-
# add fat-binary stub only when cross compiling
|
112
|
-
spec.files << "lib/puma/puma_http11.rb"
|
113
|
-
end
|
114
|
-
|
115
|
-
CLEAN.include "lib/puma/{1.8,1.9}"
|
116
|
-
CLEAN.include "lib/puma/puma_http11.rb"
|
117
|
-
end
|
118
|
-
|
119
|
-
else
|
120
|
-
|
121
|
-
# Java (JRuby)
|
122
|
-
Rake::JavaExtensionTask.new("puma_http11", HOE.spec) do |ext|
|
123
|
-
ext.lib_dir = "lib/puma"
|
124
|
-
end
|
125
|
-
|
126
|
-
end
|
127
|
-
|
128
|
-
# the following is a fat-binary stub that will be used when
|
129
|
-
# require 'puma/puma_http11' and will use either 1.8 or 1.9 version depending
|
130
|
-
# on RUBY_VERSION
|
131
|
-
file "lib/puma/puma_http11.rb" do |t|
|
132
|
-
File.open(t.name, "w") do |f|
|
133
|
-
f.puts "RUBY_VERSION =~ /(\d+.\d+)/"
|
134
|
-
f.puts 'require "puma/#{$1}/puma_http11"'
|
135
|
-
end
|
136
|
-
end
|
137
|
-
|
138
|
-
# tests require extension be compiled, but depend on the platform
|
139
|
-
if IS_JRUBY
|
140
|
-
task :test => [:java]
|
141
|
-
else
|
142
|
-
task :test => [:compile]
|
143
|
-
end
|
144
|
-
|
145
|
-
namespace :test do
|
146
|
-
desc "Run the integration tests"
|
147
|
-
task :integration do
|
148
|
-
sh "cd test/shell; sh run.sh"
|
149
|
-
end
|
150
|
-
|
151
|
-
desc "Run all tests"
|
152
|
-
if defined?(JRUBY_VERSION) and ENV['TRAVIS']
|
153
|
-
task :all => :test
|
154
|
-
else
|
155
|
-
task :all => [:test, "test:integration"]
|
156
|
-
end
|
157
|
-
end
|
158
|
-
|
data/docs/config.md
DELETED
File without changes
|
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
|
-
free(internal->top);
|
18
|
-
free(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 = malloc(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 = malloc(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
|
-
free(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 = malloc(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
|
-
free(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(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
|
-
}
|
data/lib/puma/capistrano.rb
DELETED
@@ -1,94 +0,0 @@
|
|
1
|
-
$stderr.puts "DEPRECATED: To manage puma with capistrano, use https://github.com/seuros/capistrano-puma"
|
2
|
-
|
3
|
-
Capistrano::Configuration.instance.load do
|
4
|
-
|
5
|
-
# Ensure the tmp/sockets directory is created by the deploy:setup task and
|
6
|
-
# symlinked in by the deploy:update task. This is not handled by Capistrano
|
7
|
-
# v2 but is fixed in v3.
|
8
|
-
shared_children.push('tmp/sockets')
|
9
|
-
|
10
|
-
_cset(:puma_default_hooks) { true }
|
11
|
-
_cset(:puma_cmd) { "#{fetch(:bundle_cmd, 'bundle')} exec puma" }
|
12
|
-
_cset(:pumactl_cmd) { "#{fetch(:bundle_cmd, 'bundle')} exec pumactl" }
|
13
|
-
_cset(:puma_env) { fetch(:rack_env, fetch(:rails_env, 'production')) }
|
14
|
-
_cset(:puma_state) { "#{shared_path}/sockets/puma.state" }
|
15
|
-
_cset(:puma_socket) { "unix://#{shared_path}/sockets/puma.sock" }
|
16
|
-
_cset(:puma_role) { :app }
|
17
|
-
|
18
|
-
if fetch(:puma_default_hooks)
|
19
|
-
after 'deploy:stop', 'puma:stop'
|
20
|
-
after 'deploy:start', 'puma:start'
|
21
|
-
after 'deploy:restart', 'puma:restart'
|
22
|
-
end
|
23
|
-
|
24
|
-
namespace :puma do
|
25
|
-
desc 'Start puma'
|
26
|
-
task :start, :roles => lambda { puma_role }, :on_no_matching_servers => :continue do
|
27
|
-
run "cd #{current_path} && #{puma_rails_additional_env} #{puma_cmd} #{start_options}", :pty => false
|
28
|
-
end
|
29
|
-
|
30
|
-
desc 'Stop puma'
|
31
|
-
task :stop, :roles => lambda { puma_role }, :on_no_matching_servers => :continue do
|
32
|
-
run "cd #{current_path} && #{pumactl_cmd} -S #{state_path} stop"
|
33
|
-
end
|
34
|
-
|
35
|
-
desc 'Restart puma'
|
36
|
-
task :restart, :roles => lambda { puma_role }, :on_no_matching_servers => :continue do
|
37
|
-
begin
|
38
|
-
run "cd #{current_path} && #{puma_rails_additional_env} #{pumactl_cmd} -S #{state_path} restart"
|
39
|
-
rescue Capistrano::CommandError => ex
|
40
|
-
puts "Failed to restart puma: #{ex}\nAssuming not started."
|
41
|
-
start
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
desc 'Restart puma (phased restart)'
|
46
|
-
task :phased_restart, :roles => lambda { puma_role }, :on_no_matching_servers => :continue do
|
47
|
-
begin
|
48
|
-
run "cd #{current_path} && #{puma_rails_additional_env} #{pumactl_cmd} -S #{state_path} phased-restart"
|
49
|
-
rescue Capistrano::CommandError => ex
|
50
|
-
puts "Failed to restart puma: #{ex}\nAssuming not started."
|
51
|
-
start
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
end
|
56
|
-
|
57
|
-
def start_options
|
58
|
-
if config_file
|
59
|
-
"-q -d -e #{puma_env} -C #{config_file}"
|
60
|
-
else
|
61
|
-
"-q -d -e #{puma_env} -b '#{puma_socket}' -S #{state_path} --control 'unix://#{shared_path}/sockets/pumactl.sock'"
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
def config_file
|
66
|
-
@_config_file ||= begin
|
67
|
-
file = fetch(:puma_config_file, nil)
|
68
|
-
file = "./config/puma/#{puma_env}.rb" if !file && File.exists?("./config/puma/#{puma_env}.rb")
|
69
|
-
file
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
def puma_env
|
74
|
-
fetch(:rack_env, fetch(:rails_env, 'production'))
|
75
|
-
end
|
76
|
-
|
77
|
-
#add additional env when start rails, such as : secret key, db username, db pwd or other what you want.
|
78
|
-
def puma_rails_additional_env
|
79
|
-
fetch(:puma_rails_additional_env, '')
|
80
|
-
end
|
81
|
-
|
82
|
-
def state_path
|
83
|
-
(config_file ? configuration.options[:state] : nil) || puma_state
|
84
|
-
end
|
85
|
-
|
86
|
-
def configuration
|
87
|
-
require 'puma'
|
88
|
-
require 'puma/configuration'
|
89
|
-
|
90
|
-
config = Puma::Configuration.new(:config_file => config_file)
|
91
|
-
config.load
|
92
|
-
config
|
93
|
-
end
|
94
|
-
end
|