capistrano3-puma 3.0.3 → 5.0.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/CHANGELOG.md +14 -7
- data/CONTRIBUTORS.md +46 -52
- data/LICENSE.txt +1 -1
- data/README.md +65 -5
- data/capistrano3-puma.gemspec +3 -3
- data/lib/capistrano/puma.rb +9 -5
- data/lib/capistrano/puma/daemon.rb +13 -0
- data/lib/capistrano/puma/jungle.rb +0 -6
- data/lib/capistrano/puma/monit.rb +6 -3
- data/lib/capistrano/puma/nginx.rb +2 -0
- data/lib/capistrano/puma/systemd.rb +19 -0
- data/lib/capistrano/puma/version.rb +1 -1
- data/lib/capistrano/puma/workers.rb +3 -1
- data/lib/capistrano/tasks/daemon.rake +66 -0
- data/lib/capistrano/tasks/jungle.rake +11 -1
- data/lib/capistrano/tasks/monit.rake +9 -7
- data/lib/capistrano/tasks/puma.rake +0 -79
- data/lib/capistrano/tasks/systemd.rake +59 -0
- data/lib/capistrano/tasks/workers.rake +6 -3
- data/lib/capistrano/templates/nginx_conf.erb +24 -4
- data/lib/capistrano/templates/puma-deb.erb +167 -82
- data/lib/capistrano/templates/puma.rb.erb +3 -1
- data/lib/capistrano/templates/puma.service.erb +18 -0
- data/lib/capistrano/templates/run-puma.erb +17 -6
- metadata +22 -12
@@ -0,0 +1,66 @@
|
|
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
|
+
end
|
@@ -11,9 +11,15 @@ namespace :puma do
|
|
11
11
|
if test '[ -f /etc/redhat-release ]'
|
12
12
|
#RHEL flavor OS
|
13
13
|
git_plugin.rhel_install(role)
|
14
|
+
execute "chmod +x #{fetch(:tmp_dir)}/puma"
|
15
|
+
sudo "mv #{fetch(:tmp_dir)}/puma /etc/init.d/puma"
|
16
|
+
sudo 'chkconfig --add puma'
|
14
17
|
elsif test '[ -f /etc/lsb-release ]'
|
15
18
|
#Debian flavor OS
|
16
19
|
git_plugin.debian_install(role)
|
20
|
+
execute "chmod +x #{fetch(:tmp_dir)}/puma"
|
21
|
+
sudo "mv #{fetch(:tmp_dir)}/puma /etc/init.d/puma"
|
22
|
+
sudo 'update-rc.d -f puma defaults'
|
17
23
|
else
|
18
24
|
#Some other OS
|
19
25
|
error 'This task is not supported for your OS'
|
@@ -32,7 +38,11 @@ namespace :puma do
|
|
32
38
|
desc 'Add current project to the jungle'
|
33
39
|
task :add do
|
34
40
|
on roles(fetch(:puma_role)) do|role|
|
35
|
-
|
41
|
+
begin
|
42
|
+
sudo "/etc/init.d/puma add '#{current_path}' #{fetch(:puma_user, role.user)} '#{fetch(:puma_conf)}'"
|
43
|
+
rescue => error
|
44
|
+
warn error
|
45
|
+
end
|
36
46
|
end
|
37
47
|
end
|
38
48
|
|
@@ -8,6 +8,8 @@ namespace :puma do
|
|
8
8
|
git_plugin.template_puma 'puma_monit.conf', "#{fetch(:tmp_dir)}/monit.conf", role
|
9
9
|
git_plugin.sudo_if_needed "mv #{fetch(:tmp_dir)}/monit.conf #{fetch(:puma_monit_conf_dir)}"
|
10
10
|
git_plugin.sudo_if_needed "#{fetch(:puma_monit_bin)} reload"
|
11
|
+
# Wait for Monit to be reloaded
|
12
|
+
sleep 1
|
11
13
|
end
|
12
14
|
end
|
13
15
|
|
@@ -15,10 +17,10 @@ namespace :puma do
|
|
15
17
|
task :monitor do
|
16
18
|
on roles(fetch(:puma_role)) do
|
17
19
|
begin
|
18
|
-
git_plugin.sudo_if_needed "#{fetch(:puma_monit_bin)} monitor #{puma_monit_service_name}"
|
20
|
+
git_plugin.sudo_if_needed "#{fetch(:puma_monit_bin)} monitor #{git_plugin.puma_monit_service_name}"
|
19
21
|
rescue
|
20
22
|
invoke 'puma:monit:config'
|
21
|
-
git_plugin.sudo_if_needed "#{fetch(:puma_monit_bin)} monitor #{puma_monit_service_name}"
|
23
|
+
git_plugin.sudo_if_needed "#{fetch(:puma_monit_bin)} monitor #{git_plugin.puma_monit_service_name}"
|
22
24
|
end
|
23
25
|
end
|
24
26
|
end
|
@@ -27,7 +29,7 @@ namespace :puma do
|
|
27
29
|
task :unmonitor do
|
28
30
|
on roles(fetch(:puma_role)) do
|
29
31
|
begin
|
30
|
-
git_plugin.sudo_if_needed "#{fetch(:puma_monit_bin)} unmonitor #{puma_monit_service_name}"
|
32
|
+
git_plugin.sudo_if_needed "#{fetch(:puma_monit_bin)} unmonitor #{git_plugin.puma_monit_service_name}"
|
31
33
|
rescue
|
32
34
|
# no worries here (still no monitoring)
|
33
35
|
end
|
@@ -37,23 +39,23 @@ namespace :puma do
|
|
37
39
|
desc 'Start Puma monit-service'
|
38
40
|
task :start do
|
39
41
|
on roles(fetch(:puma_role)) do
|
40
|
-
git_plugin.sudo_if_needed "#{fetch(:puma_monit_bin)} start #{puma_monit_service_name}"
|
42
|
+
git_plugin.sudo_if_needed "#{fetch(:puma_monit_bin)} start #{git_plugin.puma_monit_service_name}"
|
41
43
|
end
|
42
44
|
end
|
43
45
|
|
44
46
|
desc 'Stop Puma monit-service'
|
45
47
|
task :stop do
|
46
48
|
on roles(fetch(:puma_role)) do
|
47
|
-
git_plugin.sudo_if_needed "#{fetch(:puma_monit_bin)} stop #{puma_monit_service_name}"
|
49
|
+
git_plugin.sudo_if_needed "#{fetch(:puma_monit_bin)} stop #{git_plugin.puma_monit_service_name}"
|
48
50
|
end
|
49
51
|
end
|
50
52
|
|
51
53
|
desc 'Restart Puma monit-service'
|
52
54
|
task :restart do
|
53
55
|
on roles(fetch(:puma_role)) do
|
54
|
-
git_plugin.sudo_if_needed "#{fetch(:puma_monit_bin)} restart #{puma_monit_service_name}"
|
56
|
+
git_plugin.sudo_if_needed "#{fetch(:puma_monit_bin)} restart #{git_plugin.puma_monit_service_name}"
|
55
57
|
end
|
56
58
|
end
|
57
59
|
|
58
60
|
end
|
59
|
-
end
|
61
|
+
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,59 @@
|
|
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
|
+
unit_filename = "#{fetch(:puma_service_unit_name)}.service"
|
11
|
+
git_plugin.template_puma unit_filename, "#{fetch(:tmp_dir)}/#{unit_filename}", role
|
12
|
+
sudo "mv #{fetch(:tmp_dir)}/#{unit_filename} #{fetch(:puma_systemd_conf_dir)}"
|
13
|
+
sudo "#{fetch(:puma_systemctl_bin)} daemon-reload"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
desc 'Enable Puma systemd service'
|
18
|
+
task :enable do
|
19
|
+
on roles(fetch(:puma_role)) do
|
20
|
+
sudo "#{fetch(:puma_systemctl_bin)} enable #{fetch(:puma_service_unit_name)}"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
desc 'Disable Puma systemd service'
|
25
|
+
task :disable do
|
26
|
+
on roles(fetch(:puma_role)) do
|
27
|
+
sudo "#{fetch(:puma_systemctl_bin)} disable #{fetch(:puma_service_unit_name)}"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
desc 'Start Puma service via systemd'
|
33
|
+
task :start do
|
34
|
+
on roles(fetch(:puma_role)) do
|
35
|
+
sudo "#{fetch(:puma_systemctl_bin)} start #{fetch(:puma_service_unit_name)}"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
desc 'Stop Puma service via systemd'
|
40
|
+
task :stop do
|
41
|
+
on roles(fetch(:puma_role)) do
|
42
|
+
sudo "#{fetch(:puma_systemctl_bin)} stop #{fetch(:puma_service_unit_name)}"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
desc 'Restart Puma service via systemd'
|
47
|
+
task :restart do
|
48
|
+
on roles(fetch(:puma_role)) do
|
49
|
+
sudo "#{fetch(:puma_systemctl_bin)} restart #{fetch(:puma_service_unit_name)}"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
desc 'Get Puma service status via systemd'
|
54
|
+
task :status do
|
55
|
+
on roles(fetch(:puma_role)) do
|
56
|
+
sudo "#{fetch(:puma_systemctl_bin)} status #{fetch(:puma_service_unit_name)}"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -9,7 +9,8 @@ namespace :puma do
|
|
9
9
|
#TODO
|
10
10
|
# cleanup
|
11
11
|
# add host name/ip
|
12
|
-
|
12
|
+
puma_pid = capture("cat #{fetch(:puma_pid)}")
|
13
|
+
workers_count = capture("ps ax | grep -c 'puma: cluster worker [0-9]: #{puma_pid}'").to_i
|
13
14
|
log "Workers count : #{workers_count}"
|
14
15
|
end
|
15
16
|
end
|
@@ -23,7 +24,8 @@ namespace :puma do
|
|
23
24
|
task :more do
|
24
25
|
on roles(fetch(:puma_role)) do |role|
|
25
26
|
git_plugin.puma_switch_user(role) do
|
26
|
-
|
27
|
+
puma_pid = capture("cat #{fetch(:puma_pid)}")
|
28
|
+
execute(:kill, "-TTIN #{puma_pid}")
|
27
29
|
end
|
28
30
|
end
|
29
31
|
end
|
@@ -32,7 +34,8 @@ namespace :puma do
|
|
32
34
|
task :less do
|
33
35
|
on roles(fetch(:puma_role)) do |role|
|
34
36
|
git_plugin.puma_switch_user(role) do
|
35
|
-
|
37
|
+
puma_pid = capture("cat #{fetch(:puma_pid)}")
|
38
|
+
execute(:kill, "-TTOU #{puma_pid}")
|
36
39
|
end
|
37
40
|
end
|
38
41
|
end
|
@@ -14,16 +14,27 @@ end
|
|
14
14
|
server {
|
15
15
|
listen 80;
|
16
16
|
server_name <%= fetch(:nginx_server_name) %>;
|
17
|
-
|
17
|
+
return 301 https://$host$1$request_uri;
|
18
18
|
}
|
19
19
|
<% end -%>
|
20
20
|
|
21
21
|
server {
|
22
22
|
<% if fetch(:nginx_use_ssl) -%>
|
23
|
-
|
24
|
-
ssl
|
23
|
+
<% if fetch(:nginx_use_http2) -%>
|
24
|
+
listen 443 ssl http2;
|
25
|
+
<% else -%>
|
26
|
+
listen 443 ssl;
|
27
|
+
<% end -%>
|
28
|
+
<% if fetch(:nginx_ssl_certificate) -%>
|
29
|
+
ssl_certificate <%= fetch(:nginx_ssl_certificate) %>;
|
30
|
+
<% else -%>
|
25
31
|
ssl_certificate /etc/ssl/certs/<%= fetch(:nginx_config_name) %>.crt;
|
32
|
+
<% end -%>
|
33
|
+
<% if fetch(:nginx_ssl_certificate_key) -%>
|
34
|
+
ssl_certificate_key <%= fetch(:nginx_ssl_certificate_key) %>;
|
35
|
+
<% else -%>
|
26
36
|
ssl_certificate_key /etc/ssl/private/<%= fetch(:nginx_config_name) %>.key;
|
37
|
+
<% end -%>
|
27
38
|
<% else -%>
|
28
39
|
listen 80;
|
29
40
|
<% end -%>
|
@@ -38,11 +49,20 @@ server {
|
|
38
49
|
error_page 503 @503;
|
39
50
|
|
40
51
|
location @puma_<%= fetch(:nginx_config_name) %> {
|
52
|
+
proxy_http_version 1.1;
|
41
53
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
42
|
-
proxy_set_header Host $
|
54
|
+
proxy_set_header Host $host;
|
43
55
|
proxy_redirect off;
|
56
|
+
proxy_set_header Upgrade $http_upgrade;
|
57
|
+
proxy_set_header Connection "Upgrade";
|
44
58
|
<% if fetch(:nginx_use_ssl) -%>
|
45
59
|
proxy_set_header X-Forwarded-Proto https;
|
60
|
+
<% else -%>
|
61
|
+
<% if fetch(:nginx_downstream_uses_ssl) -%>
|
62
|
+
proxy_set_header X-Forwarded-Proto https;
|
63
|
+
<% else -%>
|
64
|
+
proxy_set_header X-Forwarded-Proto http;
|
65
|
+
<% end -%>
|
46
66
|
<% end -%>
|
47
67
|
proxy_pass http://puma_<%= fetch(:nginx_config_name) %>;
|
48
68
|
# limit_req zone=one;
|
@@ -1,17 +1,16 @@
|
|
1
1
|
#! /bin/sh
|
2
2
|
### BEGIN INIT INFO
|
3
|
-
# Provides:
|
4
|
-
# Required-Start:
|
5
|
-
# Required-Stop:
|
6
|
-
# Default-Start:
|
7
|
-
# Default-Stop:
|
8
|
-
# Short-Description:
|
9
|
-
# Description:
|
10
|
-
# placed in /etc/init.d.
|
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: Puma web server
|
9
|
+
# Description: A ruby web server built for concurrency http://puma.io
|
10
|
+
# initscript to be placed in /etc/init.d.
|
11
11
|
### END INIT INFO
|
12
12
|
|
13
|
-
# Author: Darío Javier Cravero <
|
14
|
-
# Modified by: Abdelkader Boudih <'terminale@gmail.com'>
|
13
|
+
# Author: Darío Javier Cravero <dario@exordo.com>
|
15
14
|
#
|
16
15
|
# Do NOT "set -e"
|
17
16
|
|
@@ -24,6 +23,7 @@ SCRIPTNAME=/etc/init.d/$NAME
|
|
24
23
|
CONFIG=<%=fetch(:puma_jungle_conf)%>
|
25
24
|
JUNGLE=`cat $CONFIG`
|
26
25
|
RUNPUMA=<%=fetch(:puma_run_path)%>
|
26
|
+
USE_LOCAL_BUNDLE=0
|
27
27
|
|
28
28
|
# Load the VERBOSE setting and other rcS variables
|
29
29
|
. /lib/init/vars.sh
|
@@ -33,22 +33,13 @@ RUNPUMA=<%=fetch(:puma_run_path)%>
|
|
33
33
|
. /lib/lsb/init-functions
|
34
34
|
|
35
35
|
#
|
36
|
-
# Function that starts the jungle
|
36
|
+
# Function that starts the jungle
|
37
37
|
#
|
38
38
|
do_start() {
|
39
39
|
log_daemon_msg "=> Running the jungle..."
|
40
40
|
for i in $JUNGLE; do
|
41
41
|
dir=`echo $i | cut -d , -f 1`
|
42
|
-
|
43
|
-
config_file=`echo $i | cut -d , -f 3`
|
44
|
-
if [ "$config_file" = "" ]; then
|
45
|
-
config_file="$dir/config/puma.rb"
|
46
|
-
fi
|
47
|
-
log_file=`echo $i | cut -d , -f 4`
|
48
|
-
if [ "$log_file" = "" ]; then
|
49
|
-
log_file="$dir/log/puma.log"
|
50
|
-
fi
|
51
|
-
do_start_one $dir $user $config_file $log_file
|
42
|
+
do_start_one $dir
|
52
43
|
done
|
53
44
|
}
|
54
45
|
|
@@ -58,21 +49,41 @@ do_start_one() {
|
|
58
49
|
PID=`cat $PIDFILE`
|
59
50
|
# If the puma isn't running, run it, otherwise restart it.
|
60
51
|
if [ "`ps -A -o pid= | grep -c $PID`" -eq 0 ]; then
|
61
|
-
do_start_one_do $1
|
52
|
+
do_start_one_do $1
|
62
53
|
else
|
63
|
-
do_restart_one $1
|
54
|
+
do_restart_one $1
|
64
55
|
fi
|
65
56
|
else
|
66
|
-
do_start_one_do $1
|
57
|
+
do_start_one_do $1
|
67
58
|
fi
|
68
59
|
}
|
69
60
|
|
70
61
|
do_start_one_do() {
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
62
|
+
i=`grep $1 $CONFIG`
|
63
|
+
dir=`echo $i | cut -d , -f 1`
|
64
|
+
user=`echo $i | cut -d , -f 2`
|
65
|
+
config_file=`echo $i | cut -d , -f 3`
|
66
|
+
if [ "$config_file" = "" ]; then
|
67
|
+
config_file="$dir/config/puma.rb"
|
68
|
+
fi
|
69
|
+
log_file=`echo $i | cut -d , -f 4`
|
70
|
+
if [ "$log_file" = "" ]; then
|
71
|
+
log_file="$dir/log/puma.log"
|
72
|
+
fi
|
73
|
+
environment=`echo $i | cut -d , -f 5`
|
74
|
+
|
75
|
+
log_daemon_msg "--> Woke up puma $dir"
|
76
|
+
log_daemon_msg "user $user"
|
77
|
+
log_daemon_msg "log to $log_file"
|
78
|
+
|
79
|
+
if [ ! -z "$environment" ]; then
|
80
|
+
for e in $(echo "$environment" | tr ';' '\n'); do
|
81
|
+
log_daemon_msg "environment $e"
|
82
|
+
v=${e%%\=*} ; eval "$e" ; export $v
|
83
|
+
done
|
84
|
+
fi
|
85
|
+
|
86
|
+
start-stop-daemon --verbose --start --chdir $dir --chuid $user --background --exec $RUNPUMA -- $dir $config_file $log_file
|
76
87
|
}
|
77
88
|
|
78
89
|
#
|
@@ -82,8 +93,7 @@ do_stop() {
|
|
82
93
|
log_daemon_msg "=> Putting all the beasts to bed..."
|
83
94
|
for i in $JUNGLE; do
|
84
95
|
dir=`echo $i | cut -d , -f 1`
|
85
|
-
|
86
|
-
do_stop_one $dir $user
|
96
|
+
do_stop_one $dir
|
87
97
|
done
|
88
98
|
}
|
89
99
|
#
|
@@ -99,7 +109,11 @@ do_stop_one() {
|
|
99
109
|
log_daemon_msg "---> Puma $1 isn't running."
|
100
110
|
else
|
101
111
|
log_daemon_msg "---> About to kill PID `cat $PIDFILE`"
|
102
|
-
|
112
|
+
if [ "$USE_LOCAL_BUNDLE" -eq 1 ]; then
|
113
|
+
cd $1 && bundle exec pumactl --state $STATEFILE stop
|
114
|
+
else
|
115
|
+
pumactl --state $STATEFILE stop
|
116
|
+
fi
|
103
117
|
# Many daemons don't delete their pidfiles when they exit.
|
104
118
|
rm -f $PIDFILE $STATEFILE
|
105
119
|
fi
|
@@ -110,13 +124,12 @@ do_stop_one() {
|
|
110
124
|
}
|
111
125
|
|
112
126
|
#
|
113
|
-
# Function that restarts the jungle
|
127
|
+
# Function that restarts the jungle
|
114
128
|
#
|
115
129
|
do_restart() {
|
116
130
|
for i in $JUNGLE; do
|
117
131
|
dir=`echo $i | cut -d , -f 1`
|
118
|
-
|
119
|
-
do_restart_one $dir $user
|
132
|
+
do_restart_one $dir
|
120
133
|
done
|
121
134
|
}
|
122
135
|
|
@@ -125,39 +138,52 @@ do_restart() {
|
|
125
138
|
#
|
126
139
|
do_restart_one() {
|
127
140
|
PIDFILE=$1/tmp/pids/puma.pid
|
128
|
-
i=`grep $1 $CONFIG`
|
129
|
-
dir=`echo $i | cut -d , -f 1`
|
130
141
|
|
131
142
|
if [ -e $PIDFILE ]; then
|
132
143
|
log_daemon_msg "--> About to restart puma $1"
|
133
|
-
|
134
|
-
# kill -s USR2 `cat $PIDFILE`
|
144
|
+
kill -s USR2 `cat $PIDFILE`
|
135
145
|
# TODO Check if process exist
|
136
146
|
else
|
137
147
|
log_daemon_msg "--> Your puma was never playing... Let's get it out there first"
|
138
|
-
|
139
|
-
config_file=`echo $i | cut -d , -f 3`
|
140
|
-
if [ "$config_file" = "" ]; then
|
141
|
-
config_file="$dir/config/puma.rb"
|
142
|
-
do_start_one $dir $user $config_file
|
143
|
-
fi
|
144
|
-
log_file=`echo $i | cut -d , -f 4`
|
145
|
-
if [ "$log_file" = "" ]; then
|
146
|
-
log_file="$dir/log/puma.log"
|
147
|
-
fi
|
148
|
-
do_start_one $dir $user $config_file $log_file
|
148
|
+
do_start_one $1
|
149
149
|
fi
|
150
|
-
|
150
|
+
return 0
|
151
|
+
}
|
152
|
+
|
153
|
+
#
|
154
|
+
# Function that phased restarts the jungle
|
155
|
+
#
|
156
|
+
do_phased_restart() {
|
157
|
+
for i in $JUNGLE; do
|
158
|
+
dir=`echo $i | cut -d , -f 1`
|
159
|
+
do_phased_restart_one $dir
|
160
|
+
done
|
161
|
+
}
|
162
|
+
|
163
|
+
#
|
164
|
+
# Function that sends a SIGUSR1 to the daemon/service
|
165
|
+
#
|
166
|
+
do_phased_restart_one() {
|
167
|
+
PIDFILE=$1/tmp/pids/puma.pid
|
168
|
+
|
169
|
+
if [ -e $PIDFILE ]; then
|
170
|
+
log_daemon_msg "--> About to restart puma $1"
|
171
|
+
kill -s USR1 `cat $PIDFILE`
|
172
|
+
# TODO Check if process exist
|
173
|
+
else
|
174
|
+
log_daemon_msg "--> Your puma was never playing... Let's get it out there first"
|
175
|
+
do_start_one $1
|
176
|
+
fi
|
177
|
+
return 0
|
151
178
|
}
|
152
179
|
|
153
180
|
#
|
154
|
-
# Function that statuss the jungle
|
181
|
+
# Function that statuss the jungle
|
155
182
|
#
|
156
183
|
do_status() {
|
157
184
|
for i in $JUNGLE; do
|
158
185
|
dir=`echo $i | cut -d , -f 1`
|
159
|
-
|
160
|
-
do_status_one $dir $user
|
186
|
+
do_status_one $dir
|
161
187
|
done
|
162
188
|
}
|
163
189
|
|
@@ -168,16 +194,20 @@ do_status_one() {
|
|
168
194
|
PIDFILE=$1/tmp/pids/puma.pid
|
169
195
|
i=`grep $1 $CONFIG`
|
170
196
|
dir=`echo $i | cut -d , -f 1`
|
171
|
-
|
197
|
+
|
172
198
|
if [ -e $PIDFILE ]; then
|
173
199
|
log_daemon_msg "--> About to status puma $1"
|
174
|
-
|
175
|
-
|
176
|
-
|
200
|
+
if [ "$USE_LOCAL_BUNDLE" -eq 1 ]; then
|
201
|
+
cd $1 && bundle exec pumactl --state $dir/tmp/pids/puma.state stats
|
202
|
+
else
|
203
|
+
pumactl --state $dir/tmp/pids/puma.state stats
|
204
|
+
fi
|
205
|
+
# kill -s USR2 `cat $PIDFILE`
|
206
|
+
# TODO Check if process exist
|
177
207
|
else
|
178
|
-
log_daemon_msg "--> $1 isn't there :(..."
|
208
|
+
log_daemon_msg "--> $1 isn't there :(..."
|
179
209
|
fi
|
180
|
-
|
210
|
+
return 0
|
181
211
|
}
|
182
212
|
|
183
213
|
do_add() {
|
@@ -188,7 +218,7 @@ do_add() {
|
|
188
218
|
str=$1
|
189
219
|
else
|
190
220
|
echo "The app is already being managed. Remove it if you want to update its config."
|
191
|
-
exit
|
221
|
+
exit 1
|
192
222
|
fi
|
193
223
|
else
|
194
224
|
echo "The directory $1 doesn't exist."
|
@@ -215,7 +245,12 @@ do_add() {
|
|
215
245
|
str="$str,$4"
|
216
246
|
fi
|
217
247
|
|
218
|
-
#
|
248
|
+
# Environment variables
|
249
|
+
if [ "$5" != "" ]; then
|
250
|
+
str="$str,$5"
|
251
|
+
fi
|
252
|
+
|
253
|
+
# Add it to the jungle
|
219
254
|
echo $str >> $CONFIG
|
220
255
|
log_daemon_msg "Added a Puma to the jungle: $str. You still have to start it though."
|
221
256
|
}
|
@@ -232,6 +267,49 @@ do_remove() {
|
|
232
267
|
fi
|
233
268
|
}
|
234
269
|
|
270
|
+
config_bundler() {
|
271
|
+
HOME="$(eval echo ~$(id -un))"
|
272
|
+
|
273
|
+
if [ -d "$1/.rbenv/bin" ]; then
|
274
|
+
PATH="$1/.rbenv/bin:$1/.rbenv/shims:$1"
|
275
|
+
eval "$(rbenv init -)"
|
276
|
+
USE_LOCAL_BUNDLE=1
|
277
|
+
return 0
|
278
|
+
|
279
|
+
elif [ -d "/usr/local/rbenv/bin" ]; then
|
280
|
+
PATH="/usr/local/rbenv/bin:/usr/local/rbenv/shims:$PATH"
|
281
|
+
eval "$(rbenv init -)"
|
282
|
+
USE_LOCAL_BUNDLE=1
|
283
|
+
return 0
|
284
|
+
|
285
|
+
elif [ -d "$HOME/.rbenv/bin" ]; then
|
286
|
+
PATH="$HOME/.rbenv/bin:$HOME/.rbenv/shims:$PATH"
|
287
|
+
eval "$(rbenv init -)"
|
288
|
+
USE_LOCAL_BUNDLE=1
|
289
|
+
return 0
|
290
|
+
|
291
|
+
# TODO: test rvm
|
292
|
+
# elif [ -f /etc/profile.d/rvm.sh ]; then
|
293
|
+
# source /etc/profile.d/rvm.sh
|
294
|
+
# elif [ -f /usr/local/rvm/scripts/rvm ]; then
|
295
|
+
# source /etc/profile.d/rvm.sh
|
296
|
+
# elif [ -f "$HOME/.rvm/scripts/rvm" ]; then
|
297
|
+
# source "$HOME/.rvm/scripts/rvm"
|
298
|
+
# TODO: don't know what to do with chruby
|
299
|
+
# elif [ -f /usr/local/share/chruby/chruby.sh ]; then
|
300
|
+
# source /usr/local/share/chruby/chruby.sh
|
301
|
+
# if [ -f /usr/local/share/chruby/auto.sh ]; then
|
302
|
+
# source /usr/local/share/chruby/auto.sh
|
303
|
+
# fi
|
304
|
+
# if you aren't using auto, set your version here
|
305
|
+
# chruby 2.0.0
|
306
|
+
fi
|
307
|
+
|
308
|
+
return 1
|
309
|
+
}
|
310
|
+
|
311
|
+
config_bundler
|
312
|
+
|
235
313
|
case "$1" in
|
236
314
|
start)
|
237
315
|
[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
|
@@ -240,18 +318,12 @@ case "$1" in
|
|
240
318
|
else
|
241
319
|
i=`grep $2 $CONFIG`
|
242
320
|
dir=`echo $i | cut -d , -f 1`
|
243
|
-
|
244
|
-
config_file=`echo $i | cut -d , -f 3`
|
245
|
-
if [ "$config_file" = "" ]; then
|
246
|
-
config_file="$dir/config/puma.rb"
|
247
|
-
|
248
|
-
do_start_one $dir $user $config_file
|
249
|
-
fi
|
250
|
-
case "$?" in
|
251
|
-
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
|
252
|
-
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
|
253
|
-
esac
|
321
|
+
do_start_one $dir
|
254
322
|
fi
|
323
|
+
case "$?" in
|
324
|
+
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
|
325
|
+
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
|
326
|
+
esac
|
255
327
|
;;
|
256
328
|
stop)
|
257
329
|
[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
|
@@ -296,11 +368,25 @@ case "$1" in
|
|
296
368
|
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
|
297
369
|
esac
|
298
370
|
;;
|
371
|
+
phased-restart)
|
372
|
+
log_daemon_msg "Restarting (phased) $DESC" "$NAME"
|
373
|
+
if [ "$#" -eq 1 ]; then
|
374
|
+
do_phased_restart
|
375
|
+
else
|
376
|
+
i=`grep $2 $CONFIG`
|
377
|
+
dir=`echo $i | cut -d , -f 1`
|
378
|
+
do_phased_restart_one $dir
|
379
|
+
fi
|
380
|
+
case "$?" in
|
381
|
+
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
|
382
|
+
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
|
383
|
+
esac
|
384
|
+
;;
|
299
385
|
add)
|
300
386
|
if [ "$#" -lt 3 ]; then
|
301
|
-
echo "Please,
|
302
|
-
echo "
|
303
|
-
echo "
|
387
|
+
echo "Please, specify the app's directory and the user that will run it at least."
|
388
|
+
echo " Usage: $SCRIPTNAME add /path/to/app user /path/to/app/config/puma.rb /path/to/app/config/log/puma.log"
|
389
|
+
echo " config and log are optionals."
|
304
390
|
exit 1
|
305
391
|
else
|
306
392
|
do_add $2 $3 $4 $5
|
@@ -324,13 +410,12 @@ case "$1" in
|
|
324
410
|
;;
|
325
411
|
*)
|
326
412
|
echo "Usage:" >&2
|
327
|
-
echo "
|
328
|
-
echo "
|
329
|
-
echo "
|
330
|
-
echo "
|
331
|
-
echo "
|
413
|
+
echo " Run the jungle: $SCRIPTNAME {start|stop|status|restart|phased-restart}" >&2
|
414
|
+
echo " Add a Puma: $SCRIPTNAME add /path/to/app user /path/to/app/config/puma.rb /path/to/app/config/log/puma.log"
|
415
|
+
echo " config and log are optionals."
|
416
|
+
echo " Remove a Puma: $SCRIPTNAME remove /path/to/app"
|
417
|
+
echo " On a Puma: $SCRIPTNAME {start|stop|status|restart|phased-restart} PUMA-NAME" >&2
|
332
418
|
exit 3
|
333
419
|
;;
|
334
420
|
esac
|
335
421
|
:
|
336
|
-
|