capistrano3-puma 3.1.1 → 5.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.github/workflows/stale.yml +19 -0
- data/CHANGELOG.md +321 -48
- data/CONTRIBUTORS.md +1 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +1 -1
- data/README.md +78 -4
- data/Rakefile +8 -0
- data/capistrano3-puma.gemspec +1 -1
- data/lib/capistrano/puma/daemon.rb +13 -0
- data/lib/capistrano/puma/nginx.rb +2 -0
- data/lib/capistrano/puma/systemd.rb +58 -0
- data/lib/capistrano/puma/version.rb +3 -1
- data/lib/capistrano/puma.rb +49 -5
- data/lib/capistrano/tasks/daemon.rake +74 -0
- data/lib/capistrano/tasks/jungle.rake +1 -1
- data/lib/capistrano/tasks/nginx.rake +8 -0
- data/lib/capistrano/tasks/puma.rake +0 -79
- data/lib/capistrano/tasks/systemd.rake +136 -0
- data/lib/capistrano/templates/nginx_conf.erb +17 -9
- data/lib/capistrano/templates/puma.rb.erb +2 -0
- data/lib/capistrano/templates/puma.service.erb +28 -0
- data/lib/capistrano/templates/puma.socket.erb +22 -0
- metadata +22 -10
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
module Capistrano
|
|
2
|
+
class Puma::Systemd < Capistrano::Plugin
|
|
3
|
+
include PumaCommon
|
|
4
|
+
|
|
5
|
+
def register_hooks
|
|
6
|
+
after 'deploy:finished', 'puma:smart_restart'
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def define_tasks
|
|
10
|
+
eval_rakefile File.expand_path('../../tasks/systemd.rake', __FILE__)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def set_defaults
|
|
14
|
+
set_if_empty :puma_systemctl_bin, '/bin/systemctl'
|
|
15
|
+
set_if_empty :puma_service_unit_name, -> { "puma_#{fetch(:application)}_#{fetch(:stage)}" }
|
|
16
|
+
set_if_empty :puma_enable_socket_service, -> { false }
|
|
17
|
+
set_if_empty :puma_systemctl_user, :system
|
|
18
|
+
set_if_empty :puma_enable_lingering, -> { fetch(:puma_systemctl_user) != :system }
|
|
19
|
+
set_if_empty :puma_lingering_user, -> { fetch(:user) }
|
|
20
|
+
set_if_empty :puma_phased_restart, -> { false }
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def expanded_bundle_command
|
|
24
|
+
backend.capture(:echo, SSHKit.config.command_map[:bundle]).strip
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def fetch_systemd_unit_path
|
|
28
|
+
if fetch(:puma_systemctl_user) == :system
|
|
29
|
+
"/etc/systemd/system/"
|
|
30
|
+
else
|
|
31
|
+
home_dir = backend.capture :pwd
|
|
32
|
+
File.join(home_dir, ".config", "systemd", "user")
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def systemd_command(*args)
|
|
37
|
+
command = [fetch(:puma_systemctl_bin)]
|
|
38
|
+
|
|
39
|
+
unless fetch(:puma_systemctl_user) == :system
|
|
40
|
+
command << "--user"
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
command + args
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def sudo_if_needed(*command)
|
|
47
|
+
if fetch(:puma_systemctl_user) == :system
|
|
48
|
+
backend.sudo command.map(&:to_s).join(" ")
|
|
49
|
+
else
|
|
50
|
+
backend.execute(*command)
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def execute_systemd(*args)
|
|
55
|
+
sudo_if_needed(*systemd_command(*args))
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
data/lib/capistrano/puma.rb
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
require 'capistrano/bundler'
|
|
2
|
-
require
|
|
2
|
+
require 'capistrano/plugin'
|
|
3
3
|
|
|
4
4
|
module Capistrano
|
|
5
5
|
module PumaCommon
|
|
@@ -28,8 +28,7 @@ module Capistrano
|
|
|
28
28
|
end.join("\n")
|
|
29
29
|
end
|
|
30
30
|
|
|
31
|
-
|
|
32
|
-
def template_puma(from, to, role)
|
|
31
|
+
def compiled_template_puma(from, role)
|
|
33
32
|
@role = role
|
|
34
33
|
file = [
|
|
35
34
|
"lib/capistrano/templates/#{from}-#{role.hostname}-#{fetch(:stage)}.rb",
|
|
@@ -45,7 +44,50 @@ module Capistrano
|
|
|
45
44
|
File.expand_path("../templates/#{from}.rb.erb", __FILE__)
|
|
46
45
|
].detect { |path| File.file?(path) }
|
|
47
46
|
erb = File.read(file)
|
|
48
|
-
|
|
47
|
+
StringIO.new(ERB.new(erb, nil, '-').result(binding))
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def template_puma(from, to, role)
|
|
51
|
+
backend.upload! compiled_template_puma(from, role), to
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
PumaBind = Struct.new(:full_address, :kind, :address) do
|
|
55
|
+
def unix?
|
|
56
|
+
kind == :unix
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def ssl?
|
|
60
|
+
kind == :ssl
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def tcp
|
|
64
|
+
kind == :tcp || ssl?
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def local
|
|
68
|
+
if unix?
|
|
69
|
+
self
|
|
70
|
+
else
|
|
71
|
+
PumaBind.new(
|
|
72
|
+
localize_address(full_address),
|
|
73
|
+
kind,
|
|
74
|
+
localize_address(address)
|
|
75
|
+
)
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
private
|
|
80
|
+
|
|
81
|
+
def localize_address(address)
|
|
82
|
+
address.gsub(/0\.0\.0\.0(.+)/, "127.0.0.1\\1")
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def puma_binds
|
|
87
|
+
Array(fetch(:puma_bind)).map do |m|
|
|
88
|
+
etype, address = /(tcp|unix|ssl):\/{1,2}(.+)/.match(m).captures
|
|
89
|
+
PumaBind.new(m, etype.to_sym, address)
|
|
90
|
+
end
|
|
49
91
|
end
|
|
50
92
|
end
|
|
51
93
|
|
|
@@ -76,6 +118,7 @@ module Capistrano
|
|
|
76
118
|
set_if_empty :puma_preload_app, false
|
|
77
119
|
set_if_empty :puma_daemonize, false
|
|
78
120
|
set_if_empty :puma_tag, ''
|
|
121
|
+
set_if_empty :puma_restart_command, 'bundle exec puma'
|
|
79
122
|
|
|
80
123
|
# Chruby, Rbenv and RVM integration
|
|
81
124
|
append :chruby_map_bins, 'puma', 'pumactl'
|
|
@@ -88,7 +131,6 @@ module Capistrano
|
|
|
88
131
|
|
|
89
132
|
def register_hooks
|
|
90
133
|
after 'deploy:check', 'puma:check'
|
|
91
|
-
after 'deploy:finished', 'puma:smart_restart'
|
|
92
134
|
end
|
|
93
135
|
|
|
94
136
|
def puma_workers
|
|
@@ -116,6 +158,8 @@ module Capistrano
|
|
|
116
158
|
end
|
|
117
159
|
|
|
118
160
|
require 'capistrano/puma/workers'
|
|
161
|
+
require 'capistrano/puma/daemon'
|
|
162
|
+
require 'capistrano/puma/systemd'
|
|
119
163
|
require 'capistrano/puma/monit'
|
|
120
164
|
require 'capistrano/puma/jungle'
|
|
121
165
|
require 'capistrano/puma/nginx'
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
git_plugin = self
|
|
2
|
+
|
|
3
|
+
namespace :puma do
|
|
4
|
+
desc 'Start puma'
|
|
5
|
+
task :start do
|
|
6
|
+
on roles(fetch(:puma_role)) do |role|
|
|
7
|
+
git_plugin.puma_switch_user(role) do
|
|
8
|
+
if test "[ -f #{fetch(:puma_pid)} ]" and test :kill, "-0 $( cat #{fetch(:puma_pid)} )"
|
|
9
|
+
info 'Puma is already running'
|
|
10
|
+
else
|
|
11
|
+
within current_path do
|
|
12
|
+
with rack_env: fetch(:puma_env) do
|
|
13
|
+
execute :puma, "-C #{fetch(:puma_conf)} --daemon"
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
%w[halt stop status].map do |command|
|
|
22
|
+
desc "#{command} puma"
|
|
23
|
+
task command do
|
|
24
|
+
on roles (fetch(:puma_role)) do |role|
|
|
25
|
+
within current_path do
|
|
26
|
+
git_plugin.puma_switch_user(role) do
|
|
27
|
+
with rack_env: fetch(:puma_env) do
|
|
28
|
+
if test "[ -f #{fetch(:puma_pid)} ]"
|
|
29
|
+
if test :kill, "-0 $( cat #{fetch(:puma_pid)} )"
|
|
30
|
+
execute :pumactl, "-S #{fetch(:puma_state)} -F #{fetch(:puma_conf)} #{command}"
|
|
31
|
+
else
|
|
32
|
+
# delete invalid pid file , process is not running.
|
|
33
|
+
execute :rm, fetch(:puma_pid)
|
|
34
|
+
end
|
|
35
|
+
else
|
|
36
|
+
#pid file not found, so puma is probably not running or it using another pidfile
|
|
37
|
+
warn 'Puma not running'
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
%w[phased-restart restart].map do |command|
|
|
47
|
+
desc "#{command} puma"
|
|
48
|
+
task command do
|
|
49
|
+
on roles (fetch(:puma_role)) do |role|
|
|
50
|
+
within current_path do
|
|
51
|
+
git_plugin.puma_switch_user(role) do
|
|
52
|
+
with rack_env: fetch(:puma_env) do
|
|
53
|
+
if test "[ -f #{fetch(:puma_pid)} ]" and test :kill, "-0 $( cat #{fetch(:puma_pid)} )"
|
|
54
|
+
# NOTE pid exist but state file is nonsense, so ignore that case
|
|
55
|
+
execute :pumactl, "-S #{fetch(:puma_state)} -F #{fetch(:puma_conf)} #{command}"
|
|
56
|
+
else
|
|
57
|
+
# Puma is not running or state file is not present : Run it
|
|
58
|
+
invoke 'puma:start'
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
task :smart_restart do
|
|
68
|
+
if !fetch(:puma_preload_app) && fetch(:puma_workers, 0).to_i > 1
|
|
69
|
+
invoke 'puma:phased-restart'
|
|
70
|
+
else
|
|
71
|
+
invoke 'puma:restart'
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
@@ -39,7 +39,7 @@ namespace :puma do
|
|
|
39
39
|
task :add do
|
|
40
40
|
on roles(fetch(:puma_role)) do|role|
|
|
41
41
|
begin
|
|
42
|
-
sudo "/etc/init.d/puma add '#{current_path}' #{fetch(:puma_user, role.user)}"
|
|
42
|
+
sudo "/etc/init.d/puma add '#{current_path}' #{fetch(:puma_user, role.user)} '#{fetch(:puma_conf)}'"
|
|
43
43
|
rescue => error
|
|
44
44
|
warn error
|
|
45
45
|
end
|
|
@@ -11,4 +11,12 @@ namespace :puma do
|
|
|
11
11
|
end
|
|
12
12
|
end
|
|
13
13
|
end
|
|
14
|
+
|
|
15
|
+
desc 'Generate nginx configuration locally'
|
|
16
|
+
task :generate_nginx_config_locally do
|
|
17
|
+
fake_role = Struct.new(:hostname)
|
|
18
|
+
run_locally do
|
|
19
|
+
File.write('nginx.conf', git_plugin.compiled_template_puma("nginx_conf", fake_role.new("example.com")).string)
|
|
20
|
+
end
|
|
21
|
+
end
|
|
14
22
|
end
|
|
@@ -8,75 +8,6 @@ namespace :puma do
|
|
|
8
8
|
end
|
|
9
9
|
end
|
|
10
10
|
|
|
11
|
-
desc 'Start puma'
|
|
12
|
-
task :start do
|
|
13
|
-
on roles(fetch(:puma_role)) do |role|
|
|
14
|
-
git_plugin.puma_switch_user(role) do
|
|
15
|
-
if test "[ -f #{fetch(:puma_conf)} ]"
|
|
16
|
-
info "using conf file #{fetch(:puma_conf)}"
|
|
17
|
-
else
|
|
18
|
-
invoke 'puma:config'
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
if test "[ -f #{fetch(:puma_pid)} ]" and test :kill, "-0 $( cat #{fetch(:puma_pid)} )"
|
|
22
|
-
info 'Already Puma is running'
|
|
23
|
-
else
|
|
24
|
-
within current_path do
|
|
25
|
-
with rack_env: fetch(:puma_env) do
|
|
26
|
-
execute :puma, "-C #{fetch(:puma_conf)} --daemon"
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
%w[halt stop status].map do |command|
|
|
35
|
-
desc "#{command} puma"
|
|
36
|
-
task command do
|
|
37
|
-
on roles (fetch(:puma_role)) do |role|
|
|
38
|
-
within current_path do
|
|
39
|
-
git_plugin.puma_switch_user(role) do
|
|
40
|
-
with rack_env: fetch(:puma_env) do
|
|
41
|
-
if test "[ -f #{fetch(:puma_pid)} ]"
|
|
42
|
-
if test :kill, "-0 $( cat #{fetch(:puma_pid)} )"
|
|
43
|
-
execute :pumactl, "-S #{fetch(:puma_state)} -F #{fetch(:puma_conf)} #{command}"
|
|
44
|
-
else
|
|
45
|
-
# delete invalid pid file , process is not running.
|
|
46
|
-
execute :rm, fetch(:puma_pid)
|
|
47
|
-
end
|
|
48
|
-
else
|
|
49
|
-
#pid file not found, so puma is probably not running or it using another pidfile
|
|
50
|
-
warn 'Puma not running'
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
end
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
%w[phased-restart restart].map do |command|
|
|
60
|
-
desc "#{command} puma"
|
|
61
|
-
task command do
|
|
62
|
-
on roles (fetch(:puma_role)) do |role|
|
|
63
|
-
within current_path do
|
|
64
|
-
git_plugin.puma_switch_user(role) do
|
|
65
|
-
with rack_env: fetch(:puma_env) do
|
|
66
|
-
if test "[ -f #{fetch(:puma_pid)} ]" and test :kill, "-0 $( cat #{fetch(:puma_pid)} )"
|
|
67
|
-
# NOTE pid exist but state file is nonsense, so ignore that case
|
|
68
|
-
execute :pumactl, "-S #{fetch(:puma_state)} -F #{fetch(:puma_conf)} #{command}"
|
|
69
|
-
else
|
|
70
|
-
# Puma is not running or state file is not present : Run it
|
|
71
|
-
invoke 'puma:start'
|
|
72
|
-
end
|
|
73
|
-
end
|
|
74
|
-
end
|
|
75
|
-
end
|
|
76
|
-
end
|
|
77
|
-
end
|
|
78
|
-
end
|
|
79
|
-
|
|
80
11
|
task :check do
|
|
81
12
|
on roles(fetch(:puma_role)) do |role|
|
|
82
13
|
#Create puma.rb for new deployments
|
|
@@ -87,14 +18,4 @@ namespace :puma do
|
|
|
87
18
|
end
|
|
88
19
|
end
|
|
89
20
|
end
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
task :smart_restart do
|
|
93
|
-
if !git_plugin.puma_preload_app? && git_plugin.puma_workers.to_i > 1
|
|
94
|
-
invoke 'puma:phased-restart'
|
|
95
|
-
else
|
|
96
|
-
invoke 'puma:restart'
|
|
97
|
-
end
|
|
98
|
-
end
|
|
99
|
-
|
|
100
21
|
end
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
git_plugin = self
|
|
4
|
+
|
|
5
|
+
namespace :puma do
|
|
6
|
+
namespace :systemd do
|
|
7
|
+
desc 'Config Puma systemd service'
|
|
8
|
+
task :config do
|
|
9
|
+
on roles(fetch(:puma_role)) do |role|
|
|
10
|
+
|
|
11
|
+
upload_compiled_template = lambda do |template_name, unit_filename|
|
|
12
|
+
git_plugin.template_puma template_name, "#{fetch(:tmp_dir)}/#{unit_filename}", role
|
|
13
|
+
systemd_path = fetch(:puma_systemd_conf_dir, git_plugin.fetch_systemd_unit_path)
|
|
14
|
+
if fetch(:puma_systemctl_user) == :system
|
|
15
|
+
sudo "mv #{fetch(:tmp_dir)}/#{unit_filename} #{systemd_path}"
|
|
16
|
+
else
|
|
17
|
+
execute :mkdir, "-p", systemd_path
|
|
18
|
+
execute :mv, "#{fetch(:tmp_dir)}/#{unit_filename}", "#{systemd_path}"
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
upload_compiled_template.call("puma.service", "#{fetch(:puma_service_unit_name)}.service")
|
|
23
|
+
|
|
24
|
+
if fetch(:puma_enable_socket_service)
|
|
25
|
+
upload_compiled_template.call("puma.socket", "#{fetch(:puma_service_unit_name)}.socket")
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# Reload systemd
|
|
29
|
+
git_plugin.execute_systemd("daemon-reload")
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
desc 'Generate service configuration locally'
|
|
34
|
+
task :generate_config_locally do
|
|
35
|
+
fake_role = Struct.new(:hostname)
|
|
36
|
+
run_locally do
|
|
37
|
+
File.write('puma.service', git_plugin.compiled_template_puma("puma.service", fake_role.new("example.com")).string)
|
|
38
|
+
if fetch(:puma_enable_socket_service)
|
|
39
|
+
File.write('puma.socket', git_plugin.compiled_template_puma("puma.socket", fake_role.new("example.com")).string)
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
desc 'Enable Puma systemd service'
|
|
45
|
+
task :enable do
|
|
46
|
+
on roles(fetch(:puma_role)) do
|
|
47
|
+
git_plugin.execute_systemd("enable", fetch(:puma_service_unit_name))
|
|
48
|
+
git_plugin.execute_systemd("enable", fetch(:puma_service_unit_name) + ".socket") if fetch(:puma_enable_socket_service)
|
|
49
|
+
|
|
50
|
+
if fetch(:puma_systemctl_user) != :system && fetch(:puma_enable_lingering)
|
|
51
|
+
execute :loginctl, "enable-linger", fetch(:puma_lingering_user)
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
desc 'Disable Puma systemd service'
|
|
57
|
+
task :disable do
|
|
58
|
+
on roles(fetch(:puma_role)) do
|
|
59
|
+
git_plugin.execute_systemd("disable", fetch(:puma_service_unit_name))
|
|
60
|
+
git_plugin.execute_systemd("disable", fetch(:puma_service_unit_name) + ".socket") if fetch(:puma_enable_socket_service)
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
desc 'Stop Puma socket via systemd'
|
|
65
|
+
task :stop_socket do
|
|
66
|
+
on roles(fetch(:puma_role)) do
|
|
67
|
+
git_plugin.execute_systemd("stop", fetch(:puma_service_unit_name) + ".socket")
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
desc 'Restart Puma socket via systemd'
|
|
72
|
+
task :restart_socket do
|
|
73
|
+
on roles(fetch(:puma_role)) do
|
|
74
|
+
git_plugin.execute_systemd("restart", fetch(:puma_service_unit_name) + ".socket")
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
desc 'Start Puma service via systemd'
|
|
80
|
+
task :start do
|
|
81
|
+
on roles(fetch(:puma_role)) do
|
|
82
|
+
git_plugin.execute_systemd("start", fetch(:puma_service_unit_name))
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
desc 'Stop Puma service via systemd'
|
|
87
|
+
task :stop do
|
|
88
|
+
on roles(fetch(:puma_role)) do
|
|
89
|
+
git_plugin.execute_systemd("stop", fetch(:puma_service_unit_name))
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
desc 'Restarts or reloads Puma service via systemd'
|
|
94
|
+
task :smart_restart do
|
|
95
|
+
if fetch(:puma_phased_restart)
|
|
96
|
+
invoke 'puma:reload'
|
|
97
|
+
else
|
|
98
|
+
invoke 'puma:restart'
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
desc 'Restart Puma service via systemd'
|
|
103
|
+
task :restart do
|
|
104
|
+
on roles(fetch(:puma_role)) do
|
|
105
|
+
git_plugin.execute_systemd("restart", fetch(:puma_service_unit_name))
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
desc 'Reload Puma service via systemd'
|
|
110
|
+
task :reload do
|
|
111
|
+
on roles(fetch(:puma_role)) do
|
|
112
|
+
service_ok = if fetch(:puma_systemctl_user) == :system
|
|
113
|
+
execute("#{fetch(:puma_systemctl_bin)} status #{fetch(:puma_service_unit_name)} > /dev/null", raise_on_non_zero_exit: false)
|
|
114
|
+
else
|
|
115
|
+
execute("#{fetch(:puma_systemctl_bin)} --user status #{fetch(:puma_service_unit_name)} > /dev/null", raise_on_non_zero_exit: false)
|
|
116
|
+
end
|
|
117
|
+
cmd = 'reload'
|
|
118
|
+
if !service_ok
|
|
119
|
+
cmd = 'restart'
|
|
120
|
+
end
|
|
121
|
+
if fetch(:puma_systemctl_user) == :system
|
|
122
|
+
sudo "#{fetch(:puma_systemctl_bin)} #{cmd} #{fetch(:puma_service_unit_name)}"
|
|
123
|
+
else
|
|
124
|
+
execute "#{fetch(:puma_systemctl_bin)}", "--user", cmd, fetch(:puma_service_unit_name)
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
desc 'Get Puma service status via systemd'
|
|
130
|
+
task :status do
|
|
131
|
+
on roles(fetch(:puma_role)) do
|
|
132
|
+
git_plugin.execute_systemd("status", fetch(:puma_service_unit_name))
|
|
133
|
+
git_plugin.execute_systemd("status", fetch(:puma_service_unit_name) + ".socket") if fetch(:puma_enable_socket_service)
|
|
134
|
+
end
|
|
135
|
+
end
|
|
136
|
+
end
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
upstream puma_<%= fetch(:nginx_config_name) %> { <%
|
|
2
|
-
@backends =
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
@backends = puma_binds.map do |bind|
|
|
3
|
+
if bind.unix?
|
|
4
|
+
"server unix:#{bind.address} #{fetch(:nginx_socket_flags)};"
|
|
5
|
+
else
|
|
6
|
+
"server #{bind.local.address} #{fetch(:nginx_http_flags)};"
|
|
7
|
+
end
|
|
8
8
|
end
|
|
9
|
-
end
|
|
10
9
|
%><% @backends.each do |server| %>
|
|
11
10
|
<%= server %><% end %>
|
|
12
11
|
}
|
|
@@ -20,8 +19,11 @@ server {
|
|
|
20
19
|
|
|
21
20
|
server {
|
|
22
21
|
<% if fetch(:nginx_use_ssl) -%>
|
|
23
|
-
|
|
24
|
-
ssl
|
|
22
|
+
<% if fetch(:nginx_use_http2) -%>
|
|
23
|
+
listen 443 ssl http2;
|
|
24
|
+
<% else -%>
|
|
25
|
+
listen 443 ssl;
|
|
26
|
+
<% end -%>
|
|
25
27
|
<% if fetch(:nginx_ssl_certificate) -%>
|
|
26
28
|
ssl_certificate <%= fetch(:nginx_ssl_certificate) %>;
|
|
27
29
|
<% else -%>
|
|
@@ -46,7 +48,9 @@ server {
|
|
|
46
48
|
error_page 503 @503;
|
|
47
49
|
|
|
48
50
|
location @puma_<%= fetch(:nginx_config_name) %> {
|
|
51
|
+
proxy_http_version 1.1;
|
|
49
52
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
53
|
+
proxy_set_header X-Forwarded-Proto $scheme;
|
|
50
54
|
proxy_set_header Host $host;
|
|
51
55
|
proxy_redirect off;
|
|
52
56
|
proxy_set_header Upgrade $http_upgrade;
|
|
@@ -54,7 +58,11 @@ server {
|
|
|
54
58
|
<% if fetch(:nginx_use_ssl) -%>
|
|
55
59
|
proxy_set_header X-Forwarded-Proto https;
|
|
56
60
|
<% else -%>
|
|
61
|
+
<% if fetch(:nginx_downstream_uses_ssl) -%>
|
|
62
|
+
proxy_set_header X-Forwarded-Proto https;
|
|
63
|
+
<% else -%>
|
|
57
64
|
proxy_set_header X-Forwarded-Proto http;
|
|
65
|
+
<% end -%>
|
|
58
66
|
<% end -%>
|
|
59
67
|
proxy_pass http://puma_<%= fetch(:nginx_config_name) %>;
|
|
60
68
|
# limit_req zone=one;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
[Unit]
|
|
2
|
+
Description=Puma HTTP Server for <%= "#{fetch(:application)} (#{fetch(:stage)})" %>
|
|
3
|
+
After=network.target
|
|
4
|
+
<%= "Requires=#{fetch(:puma_service_unit_name)}.socket" if fetch(:puma_enable_socket_service) %>
|
|
5
|
+
|
|
6
|
+
[Service]
|
|
7
|
+
Type=simple
|
|
8
|
+
<%="User=#{puma_user(@role)}" if fetch(:puma_systemctl_user) == :system %>
|
|
9
|
+
WorkingDirectory=<%= current_path %>
|
|
10
|
+
# Support older bundler versions where file descriptors weren't kept
|
|
11
|
+
# See https://github.com/rubygems/rubygems/issues/3254
|
|
12
|
+
ExecStart=<%= expanded_bundle_command %> exec --keep-file-descriptors puma -C <%= fetch(:puma_conf) %>
|
|
13
|
+
ExecReload=/bin/kill -USR1 $MAINPID
|
|
14
|
+
StandardOutput=append:<%= fetch(:puma_access_log) %>
|
|
15
|
+
StandardError=append:<%= fetch(:puma_error_log) %>
|
|
16
|
+
<%="EnvironmentFile=#{fetch(:puma_service_unit_env_file)}" if fetch(:puma_service_unit_env_file) %>
|
|
17
|
+
|
|
18
|
+
<% fetch(:puma_service_unit_env_vars, []).each do |environment_variable| %>
|
|
19
|
+
<%="Environment=#{environment_variable}" %>
|
|
20
|
+
<% end %>
|
|
21
|
+
|
|
22
|
+
Restart=always
|
|
23
|
+
RestartSec=1
|
|
24
|
+
|
|
25
|
+
SyslogIdentifier=puma
|
|
26
|
+
|
|
27
|
+
[Install]
|
|
28
|
+
WantedBy=<%=(fetch(:puma_systemctl_user) == :system) ? "multi-user.target" : "default.target"%>
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
[Unit]
|
|
2
|
+
Description=Puma HTTP Server Accept Sockets for <%= "#{fetch(:application)} (#{fetch(:stage)})" %>
|
|
3
|
+
|
|
4
|
+
[Socket]
|
|
5
|
+
<% puma_binds.each do |bind| -%>
|
|
6
|
+
<%= "ListenStream=#{bind.local.address}" %>
|
|
7
|
+
<% end -%>
|
|
8
|
+
|
|
9
|
+
# Don't let systemd accept the request, wait for Puma to do that.
|
|
10
|
+
# Systemd will start the puma service upon first request if it wasn't started.
|
|
11
|
+
#
|
|
12
|
+
# You might also want to set your Nginx upstream to have a fail_timeout large enough to accomodate your app's
|
|
13
|
+
# startup time.
|
|
14
|
+
Accept=no
|
|
15
|
+
<%= "NoDelay=true" if fetch(:puma_systemctl_user) == :system %>
|
|
16
|
+
ReusePort=true
|
|
17
|
+
Backlog=1024
|
|
18
|
+
|
|
19
|
+
SyslogIdentifier=puma_socket
|
|
20
|
+
|
|
21
|
+
[Install]
|
|
22
|
+
WantedBy=sockets.target
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: capistrano3-puma
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 5.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Abdelkader Boudih
|
|
8
|
-
autorequire:
|
|
8
|
+
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2021-09-11 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: capistrano
|
|
@@ -42,16 +42,22 @@ dependencies:
|
|
|
42
42
|
name: puma
|
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
|
44
44
|
requirements:
|
|
45
|
-
- - "
|
|
45
|
+
- - ">="
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '4.0'
|
|
48
|
+
- - "<"
|
|
46
49
|
- !ruby/object:Gem::Version
|
|
47
|
-
version: '
|
|
50
|
+
version: '6.0'
|
|
48
51
|
type: :runtime
|
|
49
52
|
prerelease: false
|
|
50
53
|
version_requirements: !ruby/object:Gem::Requirement
|
|
51
54
|
requirements:
|
|
52
|
-
- - "
|
|
55
|
+
- - ">="
|
|
56
|
+
- !ruby/object:Gem::Version
|
|
57
|
+
version: '4.0'
|
|
58
|
+
- - "<"
|
|
53
59
|
- !ruby/object:Gem::Version
|
|
54
|
-
version: '
|
|
60
|
+
version: '6.0'
|
|
55
61
|
description: Puma integration for Capistrano 3
|
|
56
62
|
email:
|
|
57
63
|
- Terminale@gmail.com
|
|
@@ -59,6 +65,7 @@ executables: []
|
|
|
59
65
|
extensions: []
|
|
60
66
|
extra_rdoc_files: []
|
|
61
67
|
files:
|
|
68
|
+
- ".github/workflows/stale.yml"
|
|
62
69
|
- ".gitignore"
|
|
63
70
|
- CHANGELOG.md
|
|
64
71
|
- CONTRIBUTORS.md
|
|
@@ -68,20 +75,26 @@ files:
|
|
|
68
75
|
- Rakefile
|
|
69
76
|
- capistrano3-puma.gemspec
|
|
70
77
|
- lib/capistrano/puma.rb
|
|
78
|
+
- lib/capistrano/puma/daemon.rb
|
|
71
79
|
- lib/capistrano/puma/jungle.rb
|
|
72
80
|
- lib/capistrano/puma/monit.rb
|
|
73
81
|
- lib/capistrano/puma/nginx.rb
|
|
82
|
+
- lib/capistrano/puma/systemd.rb
|
|
74
83
|
- lib/capistrano/puma/version.rb
|
|
75
84
|
- lib/capistrano/puma/workers.rb
|
|
85
|
+
- lib/capistrano/tasks/daemon.rake
|
|
76
86
|
- lib/capistrano/tasks/jungle.rake
|
|
77
87
|
- lib/capistrano/tasks/monit.rake
|
|
78
88
|
- lib/capistrano/tasks/nginx.rake
|
|
79
89
|
- lib/capistrano/tasks/puma.rake
|
|
90
|
+
- lib/capistrano/tasks/systemd.rake
|
|
80
91
|
- lib/capistrano/tasks/workers.rake
|
|
81
92
|
- lib/capistrano/templates/nginx_conf.erb
|
|
82
93
|
- lib/capistrano/templates/puma-deb.erb
|
|
83
94
|
- lib/capistrano/templates/puma-rpm.erb
|
|
84
95
|
- lib/capistrano/templates/puma.rb.erb
|
|
96
|
+
- lib/capistrano/templates/puma.service.erb
|
|
97
|
+
- lib/capistrano/templates/puma.socket.erb
|
|
85
98
|
- lib/capistrano/templates/puma_monit.conf.erb
|
|
86
99
|
- lib/capistrano/templates/run-puma.erb
|
|
87
100
|
- lib/capistrano3-puma.rb
|
|
@@ -107,9 +120,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
107
120
|
- !ruby/object:Gem::Version
|
|
108
121
|
version: '0'
|
|
109
122
|
requirements: []
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
signing_key:
|
|
123
|
+
rubygems_version: 3.0.3
|
|
124
|
+
signing_key:
|
|
113
125
|
specification_version: 4
|
|
114
126
|
summary: Puma integration for Capistrano
|
|
115
127
|
test_files: []
|