puma-simon 3.7.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/issue_template.md +20 -0
- data/.gitignore +18 -0
- data/.hoeignore +12 -0
- data/.travis.yml +29 -0
- data/DEPLOYMENT.md +91 -0
- data/Gemfile +12 -0
- data/History.md +1254 -0
- data/LICENSE +26 -0
- data/Manifest.txt +78 -0
- data/README.md +353 -0
- data/Rakefile +158 -0
- data/Release.md +9 -0
- data/bin/puma +10 -0
- data/bin/puma-wild +31 -0
- data/bin/pumactl +12 -0
- data/docs/nginx.md +80 -0
- data/docs/signals.md +43 -0
- data/docs/systemd.md +197 -0
- data/examples/CA/cacert.pem +23 -0
- data/examples/CA/newcerts/cert_1.pem +19 -0
- data/examples/CA/newcerts/cert_2.pem +19 -0
- data/examples/CA/private/cakeypair.pem +30 -0
- data/examples/CA/serial +1 -0
- data/examples/config.rb +200 -0
- data/examples/plugins/redis_stop_puma.rb +46 -0
- data/examples/puma/cert_puma.pem +19 -0
- data/examples/puma/client-certs/ca.crt +19 -0
- data/examples/puma/client-certs/ca.key +27 -0
- data/examples/puma/client-certs/client.crt +19 -0
- data/examples/puma/client-certs/client.key +27 -0
- data/examples/puma/client-certs/client_expired.crt +19 -0
- data/examples/puma/client-certs/client_expired.key +27 -0
- data/examples/puma/client-certs/client_unknown.crt +19 -0
- data/examples/puma/client-certs/client_unknown.key +27 -0
- data/examples/puma/client-certs/generate.rb +78 -0
- data/examples/puma/client-certs/keystore.jks +0 -0
- data/examples/puma/client-certs/server.crt +19 -0
- data/examples/puma/client-certs/server.key +27 -0
- data/examples/puma/client-certs/server.p12 +0 -0
- data/examples/puma/client-certs/unknown_ca.crt +19 -0
- data/examples/puma/client-certs/unknown_ca.key +27 -0
- data/examples/puma/csr_puma.pem +11 -0
- data/examples/puma/keystore.jks +0 -0
- data/examples/puma/puma_keypair.pem +15 -0
- data/examples/qc_config.rb +13 -0
- data/ext/puma_http11/PumaHttp11Service.java +17 -0
- data/ext/puma_http11/ext_help.h +15 -0
- data/ext/puma_http11/extconf.rb +15 -0
- data/ext/puma_http11/http11_parser.c +1069 -0
- data/ext/puma_http11/http11_parser.h +65 -0
- data/ext/puma_http11/http11_parser.java.rl +161 -0
- data/ext/puma_http11/http11_parser.rl +147 -0
- data/ext/puma_http11/http11_parser_common.rl +54 -0
- data/ext/puma_http11/io_buffer.c +155 -0
- data/ext/puma_http11/mini_ssl.c +457 -0
- data/ext/puma_http11/org/jruby/puma/Http11.java +234 -0
- data/ext/puma_http11/org/jruby/puma/Http11Parser.java +473 -0
- data/ext/puma_http11/org/jruby/puma/MiniSSL.java +339 -0
- data/ext/puma_http11/puma_http11.c +500 -0
- data/gemfiles/2.1-Gemfile +12 -0
- data/lib/puma.rb +15 -0
- data/lib/puma/accept_nonblock.rb +23 -0
- data/lib/puma/app/status.rb +66 -0
- data/lib/puma/binder.rb +402 -0
- data/lib/puma/cli.rb +220 -0
- data/lib/puma/client.rb +434 -0
- data/lib/puma/cluster.rb +510 -0
- data/lib/puma/commonlogger.rb +106 -0
- data/lib/puma/compat.rb +14 -0
- data/lib/puma/configuration.rb +364 -0
- data/lib/puma/const.rb +224 -0
- data/lib/puma/control_cli.rb +259 -0
- data/lib/puma/convenient.rb +23 -0
- data/lib/puma/daemon_ext.rb +31 -0
- data/lib/puma/delegation.rb +11 -0
- data/lib/puma/detect.rb +13 -0
- data/lib/puma/dsl.rb +486 -0
- data/lib/puma/events.rb +152 -0
- data/lib/puma/io_buffer.rb +7 -0
- data/lib/puma/java_io_buffer.rb +45 -0
- data/lib/puma/jruby_restart.rb +83 -0
- data/lib/puma/launcher.rb +410 -0
- data/lib/puma/minissl.rb +221 -0
- data/lib/puma/null_io.rb +42 -0
- data/lib/puma/plugin.rb +115 -0
- data/lib/puma/plugin/tmp_restart.rb +35 -0
- data/lib/puma/rack/backports/uri/common_193.rb +33 -0
- data/lib/puma/rack/builder.rb +298 -0
- data/lib/puma/rack/urlmap.rb +91 -0
- data/lib/puma/rack_default.rb +7 -0
- data/lib/puma/reactor.rb +210 -0
- data/lib/puma/runner.rb +171 -0
- data/lib/puma/server.rb +949 -0
- data/lib/puma/single.rb +112 -0
- data/lib/puma/state_file.rb +29 -0
- data/lib/puma/tcp_logger.rb +39 -0
- data/lib/puma/thread_pool.rb +297 -0
- data/lib/puma/util.rb +128 -0
- data/lib/rack/handler/puma.rb +78 -0
- data/puma.gemspec +52 -0
- data/test/ab_rs.rb +22 -0
- data/test/config.rb +2 -0
- data/test/config/app.rb +9 -0
- data/test/config/plugin.rb +1 -0
- data/test/config/settings.rb +2 -0
- data/test/config/state_file_testing_config.rb +14 -0
- data/test/hello-bind.ru +2 -0
- data/test/hello-delay.ru +3 -0
- data/test/hello-map.ru +3 -0
- data/test/hello-post.ru +4 -0
- data/test/hello-stuck.ru +1 -0
- data/test/hello-tcp.ru +5 -0
- data/test/hello.ru +1 -0
- data/test/hijack.ru +6 -0
- data/test/hijack2.ru +5 -0
- data/test/lobster.ru +4 -0
- data/test/shell/run.sh +24 -0
- data/test/shell/t1.rb +19 -0
- data/test/shell/t1_conf.rb +3 -0
- data/test/shell/t2.rb +17 -0
- data/test/shell/t2_conf.rb +6 -0
- data/test/shell/t3.rb +25 -0
- data/test/shell/t3_conf.rb +5 -0
- data/test/slow.ru +4 -0
- data/test/ssl_config.rb +4 -0
- data/test/test_app_status.rb +93 -0
- data/test/test_binder.rb +31 -0
- data/test/test_cli.rb +209 -0
- data/test/test_config.rb +95 -0
- data/test/test_events.rb +161 -0
- data/test/test_helper.rb +50 -0
- data/test/test_http10.rb +27 -0
- data/test/test_http11.rb +186 -0
- data/test/test_integration.rb +247 -0
- data/test/test_iobuffer.rb +39 -0
- data/test/test_minissl.rb +29 -0
- data/test/test_null_io.rb +49 -0
- data/test/test_persistent.rb +245 -0
- data/test/test_puma_server.rb +626 -0
- data/test/test_puma_server_ssl.rb +222 -0
- data/test/test_rack_handler.rb +57 -0
- data/test/test_rack_server.rb +138 -0
- data/test/test_tcp_logger.rb +39 -0
- data/test/test_tcp_rack.rb +36 -0
- data/test/test_thread_pool.rb +250 -0
- data/test/test_unix_socket.rb +35 -0
- data/test/test_web_server.rb +88 -0
- data/tools/jungle/README.md +9 -0
- data/tools/jungle/init.d/README.md +59 -0
- data/tools/jungle/init.d/puma +421 -0
- data/tools/jungle/init.d/run-puma +18 -0
- data/tools/jungle/upstart/README.md +61 -0
- data/tools/jungle/upstart/puma-manager.conf +31 -0
- data/tools/jungle/upstart/puma.conf +69 -0
- data/tools/trickletest.rb +45 -0
- metadata +297 -0
data/Rakefile
ADDED
@@ -0,0 +1,158 @@
|
|
1
|
+
require "bundler/setup"
|
2
|
+
require "hoe"
|
3
|
+
require "rake/extensiontask"
|
4
|
+
require "rake/javaextensiontask"
|
5
|
+
|
6
|
+
IS_JRUBY = defined?(RUBY_ENGINE) ? RUBY_ENGINE == "jruby" : false
|
7
|
+
|
8
|
+
Hoe.plugin :git
|
9
|
+
Hoe.plugin :ignore
|
10
|
+
|
11
|
+
HOE = Hoe.spec "puma" do
|
12
|
+
self.readme_file = "README.md"
|
13
|
+
self.urls = %w!http://puma.io https://github.com/puma/puma!
|
14
|
+
|
15
|
+
license "BSD-3-Clause"
|
16
|
+
developer 'Evan Phoenix', 'evan@phx.io'
|
17
|
+
|
18
|
+
spec_extras[:extensions] = ["ext/puma_http11/extconf.rb"]
|
19
|
+
spec_extras[:executables] = ['puma', 'pumactl']
|
20
|
+
spec_extras[:homepage] = self.urls.first
|
21
|
+
|
22
|
+
require_ruby_version ">= 1.9.3"
|
23
|
+
|
24
|
+
dependency "rack", [">= 1.1", "< 3.0"], :development
|
25
|
+
|
26
|
+
extra_dev_deps << ["rake-compiler", "~> 0.8"]
|
27
|
+
end
|
28
|
+
|
29
|
+
task :prerelease => [:clobber, :check_manifest, :test]
|
30
|
+
|
31
|
+
# hoe/test and rake-compiler don't seem to play well together, so disable
|
32
|
+
# hoe/test's .gemtest touch file thingy for now
|
33
|
+
HOE.spec.files -= [".gemtest"]
|
34
|
+
|
35
|
+
include Hoe::Git
|
36
|
+
|
37
|
+
desc "Print the current changelog."
|
38
|
+
task "changelog" do
|
39
|
+
tag = ENV["FROM"] || git_tags.last
|
40
|
+
range = [tag, "HEAD"].compact.join ".."
|
41
|
+
cmd = "git log #{range} '--format=tformat:%B|||%aN|||%aE|||'"
|
42
|
+
now = Time.new.strftime "%Y-%m-%d"
|
43
|
+
|
44
|
+
changes = `#{cmd}`.split(/\|\|\|/).each_slice(3).map { |msg, author, email|
|
45
|
+
msg.split(/\n/).reject { |s| s.empty? }.first
|
46
|
+
}.flatten.compact
|
47
|
+
|
48
|
+
$changes = Hash.new { |h,k| h[k] = [] }
|
49
|
+
|
50
|
+
codes = {
|
51
|
+
"!" => :major,
|
52
|
+
"+" => :minor,
|
53
|
+
"*" => :minor,
|
54
|
+
"-" => :bug,
|
55
|
+
"?" => :unknown,
|
56
|
+
}
|
57
|
+
|
58
|
+
codes_re = Regexp.escape codes.keys.join
|
59
|
+
|
60
|
+
changes.each do |change|
|
61
|
+
if change =~ /^\s*([#{codes_re}])\s*(.*)/ then
|
62
|
+
code, line = codes[$1], $2
|
63
|
+
else
|
64
|
+
code, line = codes["?"], change.chomp
|
65
|
+
end
|
66
|
+
|
67
|
+
$changes[code] << line
|
68
|
+
end
|
69
|
+
|
70
|
+
puts "## #{ENV['VERSION'] || 'NEXT'} / #{now}"
|
71
|
+
puts
|
72
|
+
changelog_section :major
|
73
|
+
changelog_section :minor
|
74
|
+
changelog_section :bug
|
75
|
+
changelog_section :unknown
|
76
|
+
puts
|
77
|
+
end
|
78
|
+
|
79
|
+
# generate extension code using Ragel (C and Java)
|
80
|
+
desc "Generate extension code (C and Java) using Ragel"
|
81
|
+
task :ragel
|
82
|
+
|
83
|
+
file 'ext/puma_http11/http11_parser.c' => ['ext/puma_http11/http11_parser.rl'] do |t|
|
84
|
+
begin
|
85
|
+
sh "ragel #{t.prerequisites.last} -C -G2 -I ext/puma_http11 -o #{t.name}"
|
86
|
+
rescue
|
87
|
+
fail "Could not build wrapper using Ragel (it failed or not installed?)"
|
88
|
+
end
|
89
|
+
end
|
90
|
+
task :ragel => ['ext/puma_http11/http11_parser.c']
|
91
|
+
|
92
|
+
file 'ext/puma_http11/org/jruby/puma/Http11Parser.java' => ['ext/puma_http11/http11_parser.java.rl'] do |t|
|
93
|
+
begin
|
94
|
+
sh "ragel #{t.prerequisites.last} -J -G2 -I ext/puma_http11 -o #{t.name}"
|
95
|
+
rescue
|
96
|
+
fail "Could not build wrapper using Ragel (it failed or not installed?)"
|
97
|
+
end
|
98
|
+
end
|
99
|
+
task :ragel => ['ext/puma_http11/org/jruby/puma/Http11Parser.java']
|
100
|
+
|
101
|
+
if !IS_JRUBY
|
102
|
+
|
103
|
+
# compile extensions using rake-compiler
|
104
|
+
# C (MRI, Rubinius)
|
105
|
+
Rake::ExtensionTask.new("puma_http11", HOE.spec) do |ext|
|
106
|
+
# place extension inside namespace
|
107
|
+
ext.lib_dir = "lib/puma"
|
108
|
+
|
109
|
+
ext.cross_compile = true
|
110
|
+
ext.cross_platform = ['i386-mswin32-60', 'i386-mingw32']
|
111
|
+
ext.cross_compiling do |spec|
|
112
|
+
# add fat-binary stub only when cross compiling
|
113
|
+
spec.files << "lib/puma/puma_http11.rb"
|
114
|
+
end
|
115
|
+
|
116
|
+
CLEAN.include "lib/puma/{1.8,1.9}"
|
117
|
+
CLEAN.include "lib/puma/puma_http11.rb"
|
118
|
+
end
|
119
|
+
|
120
|
+
else
|
121
|
+
|
122
|
+
# Java (JRuby)
|
123
|
+
Rake::JavaExtensionTask.new("puma_http11", HOE.spec) do |ext|
|
124
|
+
ext.lib_dir = "lib/puma"
|
125
|
+
end
|
126
|
+
|
127
|
+
end
|
128
|
+
|
129
|
+
# the following is a fat-binary stub that will be used when
|
130
|
+
# require 'puma/puma_http11' and will use either 1.8 or 1.9 version depending
|
131
|
+
# on RUBY_VERSION
|
132
|
+
file "lib/puma/puma_http11.rb" do |t|
|
133
|
+
File.open(t.name, "w") do |f|
|
134
|
+
f.puts "RUBY_VERSION =~ /(\d+.\d+)/"
|
135
|
+
f.puts 'require "puma/#{$1}/puma_http11"'
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
# tests require extension be compiled, but depend on the platform
|
140
|
+
if IS_JRUBY
|
141
|
+
task :test => [:java]
|
142
|
+
else
|
143
|
+
task :test => [:compile]
|
144
|
+
end
|
145
|
+
|
146
|
+
namespace :test do
|
147
|
+
desc "Run the integration tests"
|
148
|
+
task :integration do
|
149
|
+
sh "cd test/shell; sh run.sh"
|
150
|
+
end
|
151
|
+
|
152
|
+
desc "Run all tests"
|
153
|
+
if defined?(JRUBY_VERSION) and ENV['TRAVIS']
|
154
|
+
task :all => :test
|
155
|
+
else
|
156
|
+
task :all => [:test, "test:integration"]
|
157
|
+
end
|
158
|
+
end
|
data/Release.md
ADDED
data/bin/puma
ADDED
data/bin/puma-wild
ADDED
@@ -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
|
data/bin/pumactl
ADDED
data/docs/nginx.md
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
# Nginx configuration example file
|
2
|
+
|
3
|
+
This is a very common setup using an upstream. It was adapted from some Capistrano recipe I found on the Internet a while ago.
|
4
|
+
|
5
|
+
```
|
6
|
+
upstream myapp {
|
7
|
+
server unix:///myapp/tmp/puma.sock;
|
8
|
+
}
|
9
|
+
|
10
|
+
server {
|
11
|
+
listen 80;
|
12
|
+
server_name myapp.com;
|
13
|
+
|
14
|
+
# ~2 seconds is often enough for most folks to parse HTML/CSS and
|
15
|
+
# retrieve needed images/icons/frames, connections are cheap in
|
16
|
+
# nginx so increasing this is generally safe...
|
17
|
+
keepalive_timeout 5;
|
18
|
+
|
19
|
+
# path for static files
|
20
|
+
root /myapp/public;
|
21
|
+
access_log /myapp/log/nginx.access.log;
|
22
|
+
error_log /myapp/log/nginx.error.log info;
|
23
|
+
|
24
|
+
# this rewrites all the requests to the maintenance.html
|
25
|
+
# page if it exists in the doc root. This is for capistrano's
|
26
|
+
# disable web task
|
27
|
+
if (-f $document_root/maintenance.html) {
|
28
|
+
rewrite ^(.*)$ /maintenance.html last;
|
29
|
+
break;
|
30
|
+
}
|
31
|
+
|
32
|
+
location / {
|
33
|
+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
34
|
+
proxy_set_header Host $http_host;
|
35
|
+
|
36
|
+
# If the file exists as a static file serve it directly without
|
37
|
+
# running all the other rewrite tests on it
|
38
|
+
if (-f $request_filename) {
|
39
|
+
break;
|
40
|
+
}
|
41
|
+
|
42
|
+
# check for index.html for directory index
|
43
|
+
# if it's there on the filesystem then rewrite
|
44
|
+
# the url to add /index.html to the end of it
|
45
|
+
# and then break to send it to the next config rules.
|
46
|
+
if (-f $request_filename/index.html) {
|
47
|
+
rewrite (.*) $1/index.html break;
|
48
|
+
}
|
49
|
+
|
50
|
+
# this is the meat of the rack page caching config
|
51
|
+
# it adds .html to the end of the url and then checks
|
52
|
+
# the filesystem for that file. If it exists, then we
|
53
|
+
# rewrite the url to have explicit .html on the end
|
54
|
+
# and then send it on its way to the next config rule.
|
55
|
+
# if there is no file on the fs then it sets all the
|
56
|
+
# necessary headers and proxies to our upstream pumas
|
57
|
+
if (-f $request_filename.html) {
|
58
|
+
rewrite (.*) $1.html break;
|
59
|
+
}
|
60
|
+
|
61
|
+
if (!-f $request_filename) {
|
62
|
+
proxy_pass http://myapp;
|
63
|
+
break;
|
64
|
+
}
|
65
|
+
}
|
66
|
+
|
67
|
+
# Now this supposedly should work as it gets the filenames with querystrings that Rails provides.
|
68
|
+
# BUT there's a chance it could break the ajax calls.
|
69
|
+
location ~* \.(ico|css|gif|jpe?g|png|js)(\?[0-9]+)?$ {
|
70
|
+
expires max;
|
71
|
+
break;
|
72
|
+
}
|
73
|
+
|
74
|
+
# Error pages
|
75
|
+
# error_page 500 502 503 504 /500.html;
|
76
|
+
location = /500.html {
|
77
|
+
root /myapp/current/public;
|
78
|
+
}
|
79
|
+
}
|
80
|
+
```
|
data/docs/signals.md
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
The [unix signal](http://en.wikipedia.org/wiki/Unix_signal) is a method of sending messages between [processes](http://en.wikipedia.org/wiki/Process_(computing)). When a signal is sent, the operating system interrupts the target process's normal flow of execution. There are standard signals that are used to stop a process but there are also custom signals that can be used for other purposes. This document is an attempt to list all supported signals that Puma will respond to. In general, signals need only be sent to the master process of a cluster.
|
2
|
+
|
3
|
+
## Sending Signals
|
4
|
+
|
5
|
+
If you are new to signals it can be useful to see how they can be used. When a process is created in a *nix like operating system it will have a [PID - or process identifier](http://en.wikipedia.org/wiki/Process_identifier) that can be used to send signals to the process. For demonstration we will create an infinitely running process by tailing a file:
|
6
|
+
|
7
|
+
```sh
|
8
|
+
$ echo "foo" >> my.log
|
9
|
+
$ irb
|
10
|
+
> pid = Process.spawn 'tail -f my.log'
|
11
|
+
```
|
12
|
+
|
13
|
+
From here we can see that the tail process is running by using the `ps` command:
|
14
|
+
|
15
|
+
```sh
|
16
|
+
$ ps aux | grep tail
|
17
|
+
schneems 87152 0.0 0.0 2432772 492 s032 S+ 12:46PM 0:00.00 tail -f my.log
|
18
|
+
```
|
19
|
+
|
20
|
+
You can send a signal in Ruby using the [Process module](http://www.ruby-doc.org/core-2.1.1/Process.html#kill-method):
|
21
|
+
|
22
|
+
```
|
23
|
+
$ irb
|
24
|
+
> puts pid
|
25
|
+
=> 87152
|
26
|
+
Process.detach(pid) # http://ruby-doc.org/core-2.1.1/Process.html#method-c-detach
|
27
|
+
Process.kill("TERM", pid)
|
28
|
+
```
|
29
|
+
|
30
|
+
Now you will see via `ps` that there is no more `tail` process. Sometimes when referring to signals the `SIG` prefix will be used for instance `SIGTERM` is equivalent to sending `TERM` via `Process.kill`.
|
31
|
+
|
32
|
+
## Puma Signals
|
33
|
+
|
34
|
+
Puma cluster responds to these signals:
|
35
|
+
|
36
|
+
- `TTIN` increment the worker count by 1
|
37
|
+
- `TTOU` decrement the worker count by 1
|
38
|
+
- `TERM` send `TERM` to worker. Worker will attempt to finish then exit.
|
39
|
+
- `USR2` restart workers
|
40
|
+
- `USR1` restart workers in phases, a rolling restart.
|
41
|
+
- `HUP` reopen log files defined in stdout_redirect configuration parameter
|
42
|
+
- `INT` equivalent of sending Ctrl-C to cluster. Will attempt to finish then exit.
|
43
|
+
- `CHLD`
|
data/docs/systemd.md
ADDED
@@ -0,0 +1,197 @@
|
|
1
|
+
# systemd
|
2
|
+
|
3
|
+
[systemd](https://www.freedesktop.org/wiki/Software/systemd/) is a
|
4
|
+
commonly available init system (PID 1) on many Linux distributions. It
|
5
|
+
offers process monitoring (including automatic restarts) and other
|
6
|
+
useful features for running Puma in production. Below is a sample
|
7
|
+
puma.service configuration file for systemd:
|
8
|
+
|
9
|
+
~~~~
|
10
|
+
[Unit]
|
11
|
+
Description=Puma HTTP Server
|
12
|
+
After=network.target
|
13
|
+
|
14
|
+
# Uncomment for socket activation (see below)
|
15
|
+
# Requires=puma.socket
|
16
|
+
|
17
|
+
[Service]
|
18
|
+
# Foreground process (do not use --daemon in ExecStart or config.rb)
|
19
|
+
Type=simple
|
20
|
+
|
21
|
+
# Preferably configure a non-privileged user
|
22
|
+
# User=
|
23
|
+
|
24
|
+
# Specify the path to your puma application root
|
25
|
+
# WorkingDirectory=
|
26
|
+
|
27
|
+
# Helpful for debugging socket activation, etc.
|
28
|
+
# Environment=PUMA_DEBUG=1
|
29
|
+
|
30
|
+
# The command to start Puma
|
31
|
+
# Here we are using a binstub generated via:
|
32
|
+
# `bundle binstubs puma --path ./sbin`
|
33
|
+
# in the WorkingDirectory (replace <WD> below)
|
34
|
+
# You can alternatively use `bundle exec --keep-file-descriptors puma`
|
35
|
+
# ExecStart=<WD>/sbin/puma -b tcp://0.0.0.0:9292 -b ssl://0.0.0.0:9293?key=key.pem&cert=cert.pem
|
36
|
+
|
37
|
+
# Alternatively with a config file (in WorkingDirectory) and
|
38
|
+
# comparable `bind` directives
|
39
|
+
# ExecStart=<WD>/sbin/puma -C config.rb
|
40
|
+
|
41
|
+
Restart=always
|
42
|
+
|
43
|
+
[Install]
|
44
|
+
WantedBy=multi-user.target
|
45
|
+
~~~~
|
46
|
+
|
47
|
+
See [systemd.exec](https://www.freedesktop.org/software/systemd/man/systemd.exec.html)
|
48
|
+
for additional details.
|
49
|
+
|
50
|
+
## Socket Activation
|
51
|
+
|
52
|
+
systemd and puma also support socket activation, where systemd opens
|
53
|
+
the listening socket(s) in advance and provides them to the puma master
|
54
|
+
process on startup. Among other advantages, this keeps listening
|
55
|
+
sockets open across puma restarts and achieves graceful restarts. To
|
56
|
+
use socket activation, configure one or more `ListenStream`
|
57
|
+
sockets in a companion `*.socket` systemd config file. Here is a sample
|
58
|
+
puma.socket, matching the ports used in the above puma.service:
|
59
|
+
|
60
|
+
~~~~
|
61
|
+
[Unit]
|
62
|
+
Description=Puma HTTP Server Accept Sockets
|
63
|
+
|
64
|
+
[Socket]
|
65
|
+
ListenStream=0.0.0.0:9292
|
66
|
+
ListenStream=0.0.0.0:9293
|
67
|
+
|
68
|
+
# AF_UNIX domain socket
|
69
|
+
# SocketUser, SocketGroup, etc. may be needed for Unix domain sockets
|
70
|
+
# ListenStream=/run/puma.sock
|
71
|
+
|
72
|
+
# Socket options matching Puma defaults
|
73
|
+
NoDelay=true
|
74
|
+
ReusePort=true
|
75
|
+
Backlog=1024
|
76
|
+
|
77
|
+
[Install]
|
78
|
+
WantedBy=sockets.target
|
79
|
+
~~~~
|
80
|
+
|
81
|
+
See [systemd.socket](https://www.freedesktop.org/software/systemd/man/systemd.socket.html)
|
82
|
+
for additional configuration details.
|
83
|
+
|
84
|
+
Note that the above configurations will work with Puma in either
|
85
|
+
single process or cluster mode.
|
86
|
+
|
87
|
+
## Usage
|
88
|
+
|
89
|
+
Without socket activation, use `systemctl` as root (e.g. via `sudo`) as
|
90
|
+
with other system services:
|
91
|
+
|
92
|
+
~~~~ sh
|
93
|
+
# After installing or making changes to puma.service
|
94
|
+
systemctl daemon-reload
|
95
|
+
|
96
|
+
# Enable so it starts on boot
|
97
|
+
systemctl enable puma.service
|
98
|
+
|
99
|
+
# Initial start up.
|
100
|
+
systemctl start puma.service
|
101
|
+
|
102
|
+
# Check status
|
103
|
+
systemctl status puma.service
|
104
|
+
|
105
|
+
# A normal restart. Warning: listeners sockets will be closed
|
106
|
+
# while a new puma process initializes.
|
107
|
+
systemctl restart puma.service
|
108
|
+
~~~~
|
109
|
+
|
110
|
+
With socket activation, several but not all of these commands should
|
111
|
+
be run for both socket and service:
|
112
|
+
|
113
|
+
~~~~ sh
|
114
|
+
# After installing or making changes to either puma.socket or
|
115
|
+
# puma.service.
|
116
|
+
systemctl daemon-reload
|
117
|
+
|
118
|
+
# Enable both socket and service so they start on boot. Alternatively
|
119
|
+
# you could leave puma.service disabled and systemd will start it on
|
120
|
+
# first use (with startup lag on first request)
|
121
|
+
systemctl enable puma.socket puma.service
|
122
|
+
|
123
|
+
# Initial start up. The Requires directive (see above) ensures the
|
124
|
+
# socket is started before the service.
|
125
|
+
systemctl start puma.socket puma.service
|
126
|
+
|
127
|
+
# Check status of both socket and service.
|
128
|
+
systemctl status puma.socket puma.service
|
129
|
+
|
130
|
+
# A "hot" restart, with systemd keeping puma.socket listening and
|
131
|
+
# providing to the new puma (master) instance.
|
132
|
+
systemctl restart puma.service
|
133
|
+
|
134
|
+
# A normal restart, needed to handle changes to
|
135
|
+
# puma.socket, such as changing the ListenStream ports. Note
|
136
|
+
# daemon-reload (above) should be run first.
|
137
|
+
systemctl restart puma.socket puma.service
|
138
|
+
~~~~
|
139
|
+
|
140
|
+
Here is sample output from `systemctl status` with both service and
|
141
|
+
socket running:
|
142
|
+
|
143
|
+
~~~~
|
144
|
+
● puma.socket - Puma HTTP Server Accept Sockets
|
145
|
+
Loaded: loaded (/etc/systemd/system/puma.socket; enabled; vendor preset: enabled)
|
146
|
+
Active: active (running) since Thu 2016-04-07 08:40:19 PDT; 1h 2min ago
|
147
|
+
Listen: 0.0.0.0:9233 (Stream)
|
148
|
+
0.0.0.0:9234 (Stream)
|
149
|
+
|
150
|
+
Apr 07 08:40:19 hx systemd[874]: Listening on Puma HTTP Server Accept Sockets.
|
151
|
+
|
152
|
+
● puma.service - Puma HTTP Server
|
153
|
+
Loaded: loaded (/etc/systemd/system/puma.service; enabled; vendor preset: enabled)
|
154
|
+
Active: active (running) since Thu 2016-04-07 08:40:19 PDT; 1h 2min ago
|
155
|
+
Main PID: 28320 (ruby)
|
156
|
+
CGroup: /system.slice/puma.service
|
157
|
+
├─28320 puma 3.3.0 (tcp://0.0.0.0:9233,ssl://0.0.0.0:9234?key=key.pem&cert=cert.pem) [app]
|
158
|
+
├─28323 puma: cluster worker 0: 28320 [app]
|
159
|
+
└─28327 puma: cluster worker 1: 28320 [app]
|
160
|
+
|
161
|
+
Apr 07 08:40:19 hx puma[28320]: Puma starting in cluster mode...
|
162
|
+
Apr 07 08:40:19 hx puma[28320]: * Version 3.3.0 (ruby 2.2.4-p230), codename: Jovial Platypus
|
163
|
+
Apr 07 08:40:19 hx puma[28320]: * Min threads: 0, max threads: 16
|
164
|
+
Apr 07 08:40:19 hx puma[28320]: * Environment: production
|
165
|
+
Apr 07 08:40:19 hx puma[28320]: * Process workers: 2
|
166
|
+
Apr 07 08:40:19 hx puma[28320]: * Phased restart available
|
167
|
+
Apr 07 08:40:19 hx puma[28320]: * Activated tcp://0.0.0.0:9233
|
168
|
+
Apr 07 08:40:19 hx puma[28320]: * Activated ssl://0.0.0.0:9234?key=key.pem&cert=cert.pem
|
169
|
+
Apr 07 08:40:19 hx puma[28320]: Use Ctrl-C to stop
|
170
|
+
~~~~
|
171
|
+
|
172
|
+
## Alternative background process configuration
|
173
|
+
|
174
|
+
If Capistrano and [capistrano3-puma](https://github.com/seuros/capistrano-puma) tasks are used you can use the following configuration. In this case, you would skip systemd Socket Activation, since Puma handles the socket by itself:
|
175
|
+
|
176
|
+
~~~~
|
177
|
+
[Service]
|
178
|
+
# Background process configuration (use with --daemon in ExecStart)
|
179
|
+
Type=forking
|
180
|
+
|
181
|
+
# To learn which exact command is to be used to execute at "ExecStart" of this
|
182
|
+
# Service, ask Capistrano: `cap <stage> puma:start --dry-run`. Your result
|
183
|
+
# may differ from this example, for example if you use a Ruby version
|
184
|
+
# manager. `<WD>` is short for "your working directory". Replace it with your
|
185
|
+
# path.
|
186
|
+
ExecStart=bundle exec puma -C <WD>/shared/puma.rb --daemon
|
187
|
+
|
188
|
+
# To learn which exact command is to be used to execute at "ExecStop" of this
|
189
|
+
# Service, ask Capistrano: `cap <stage> puma:stop --dry-run`. Your result
|
190
|
+
# may differ from this example, for example if you use a Ruby version
|
191
|
+
# manager. `<WD>` is short for "your working directory". Replace it with your
|
192
|
+
# path.
|
193
|
+
ExecStop=bundle exec pumactl -S <WD>/shared/tmp/pids/puma.state stop
|
194
|
+
|
195
|
+
# PIDFile setting is required in order to work properly
|
196
|
+
PIDFile=<WD>/shared/tmp/pids/puma.pid
|
197
|
+
~~~~
|