capistrano-pumaio 0.0.18 → 3.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 +7 -0
- data/Gemfile +5 -4
- data/Gemfile.lock +64 -51
- data/LICENSE +1 -1
- data/README.md +20 -5
- data/Rakefile +13 -11
- data/VERSION +1 -1
- data/capistrano-pumaio.gemspec +33 -25
- data/lib/capistrano/helpers/puma/monit.rb +20 -0
- data/lib/capistrano/helpers/puma/nginx.rb +13 -0
- data/lib/capistrano/helpers/puma/template_paths.rb +16 -0
- data/lib/capistrano/puma.rb +13 -3
- data/lib/capistrano/tasks/config.rake +68 -0
- data/lib/capistrano/tasks/monit.rake +66 -0
- data/lib/capistrano/tasks/nginx.rake +119 -0
- data/lib/capistrano/tasks/nginx_config.rake +63 -0
- data/lib/capistrano/tasks/runit.rake +179 -0
- data/templates/monit/puma.conf.erb +11 -12
- data/templates/nginx/application.conf.erb +35 -70
- data/templates/nginx/htpasswd.erb +1 -2
- data/templates/puma-config.rb.erb +26 -0
- data/templates/runit/control/q.erb +7 -0
- data/templates/runit/finish.erb +13 -14
- data/templates/runit/log/run.erb +9 -0
- data/templates/runit/run.erb +7 -8
- metadata +51 -45
- data/lib/capistrano/puma/config.rb +0 -56
- data/lib/capistrano/puma/monit.rb +0 -70
- data/lib/capistrano/puma/nginx.rb +0 -128
- data/lib/capistrano/puma/runit.rb +0 -145
- data/templates/runit/config.rb.erb +0 -20
- data/templates/runit/control-q.erb +0 -8
- data/templates/runit/log-run.erb +0 -10
@@ -1,56 +0,0 @@
|
|
1
|
-
require 'capistrano/base_helper/base_helper'
|
2
|
-
Capistrano::Configuration.instance(true).load do
|
3
|
-
_cset :puma_runit_service_name, "puma"
|
4
|
-
_cset :puma_workers, 2 # Must use a minimum of 1 worker (cluster mode, else restart/stop fails in the state file?)
|
5
|
-
_cset :puma_min_threads, 2
|
6
|
-
_cset :puma_max_threads, 8
|
7
|
-
|
8
|
-
_cset :puma_bin, 'bundle exec puma'
|
9
|
-
_cset :puma_control, 'bundle exec pumactl'
|
10
|
-
|
11
|
-
# Control files
|
12
|
-
_cset :puma_socket_file, defer { "#{File.join(fetch(:sockets_path), "puma.sock")}" }
|
13
|
-
_cset :puma_socket_url, defer { "unix://#{fetch(:puma_socket_file)}" }
|
14
|
-
_cset :puma_pid_file, defer { File.join(fetch(:pids_path), "puma.pid") }
|
15
|
-
_cset :puma_state_file, defer { File.join(fetch(:sockets_path), "puma.state") }
|
16
|
-
_cset :puma_control_file, defer { "#{File.join(fetch(:sockets_path), "pumactl.sock")}" }
|
17
|
-
_cset :puma_control_url, defer { "unix://#{fetch(:puma_control_file)}" }
|
18
|
-
|
19
|
-
_cset :puma_use_preload_app, true # This must be set to false if phased restarts should be used
|
20
|
-
|
21
|
-
_cset :puma_activate_control_app, true
|
22
|
-
|
23
|
-
_cset :puma_on_restart_active, true
|
24
|
-
|
25
|
-
# Logging to path
|
26
|
-
_cset :puma_log_path, defer {"/var/log/service/#{fetch(:user)}/#{fetch(:application)}_#{Capistrano::BaseHelper.environment}/puma"}
|
27
|
-
|
28
|
-
# Configuration files
|
29
|
-
_cset :puma_local_config, File.join(File.expand_path(File.join(File.dirname(__FILE__),"../../../templates", "runit")), "config.rb.erb")
|
30
|
-
|
31
|
-
# The remote location of puma's config file. Used by runit when starting puma
|
32
|
-
_cset :puma_remote_config, defer {File.join(shared_path, "config", "puma.rb")}
|
33
|
-
|
34
|
-
# runit defaults
|
35
|
-
_cset :puma_restart_interval, defer {fetch(:runit_restart_interval)}
|
36
|
-
_cset :puma_restart_count, defer {fetch(:runit_restart_count)}
|
37
|
-
_cset :puma_autorestart_clear_interval, defer {fetch(:runit_autorestart_clear_interval)}
|
38
|
-
|
39
|
-
# runit paths
|
40
|
-
_cset :puma_runit_local_run, File.join(File.expand_path(File.join(File.dirname(__FILE__),"../../../templates", "runit", )), "run.erb")
|
41
|
-
_cset :puma_runit_local_finish, File.join(File.expand_path(File.join(File.dirname(__FILE__),"../../../templates", "runit", )), "finish.erb")
|
42
|
-
_cset :puma_runit_control_q, File.join(File.expand_path(File.join(File.dirname(__FILE__),"../../../templates", "runit")), "control-q.erb")
|
43
|
-
_cset :puma_runit_local_log_run, File.join(File.expand_path(File.join(File.dirname(__FILE__),"../../../templates", "runit")), "log-run.erb")
|
44
|
-
|
45
|
-
# monit configuration
|
46
|
-
_cset :puma_monit_service_name, defer { "#{fetch(:user)}_#{fetch(:application)}_#{Capistrano::BaseHelper.environment}_puma" }
|
47
|
-
_cset :puma_monit_start_command, defer {"/bin/bash -c '[ ! -h #{Capistrano::RunitBase.service_path(fetch(:puma_runit_service_name))}/run ] || /usr/bin/sv start #{Capistrano::RunitBase.service_path(fetch(:puma_runit_service_name))}'"}
|
48
|
-
_cset :puma_monit_stop_command, defer {"/usr/bin/sv -w 12 force-stop #{Capistrano::RunitBase.service_path(fetch(:puma_runit_service_name))}"}
|
49
|
-
_cset :puma_monit_memory_alert_threshold, "150.0 MB for 2 cycles"
|
50
|
-
_cset :puma_monit_memory_restart_threshold, "175.0 MB for 3 cycles"
|
51
|
-
_cset :puma_monit_cpu_alert_threshold, "90% for 2 cycles"
|
52
|
-
_cset :puma_monit_cpu_restart_threshold, "95% for 5 cycles"
|
53
|
-
|
54
|
-
_cset :puma_local_monit_config, File.join(File.expand_path(File.join(File.dirname(__FILE__),"../../../templates", "monit")), "puma.conf.erb")
|
55
|
-
|
56
|
-
end
|
@@ -1,70 +0,0 @@
|
|
1
|
-
# Puma - Monit
|
2
|
-
# Setup and management of Monit for Puma
|
3
|
-
#
|
4
|
-
require 'capistrano/puma/config'
|
5
|
-
require 'capistrano/base_helper/monit_base'
|
6
|
-
|
7
|
-
Capistrano::Configuration.instance(true).load do
|
8
|
-
after "monit:setup", "puma:monit:setup"
|
9
|
-
after "puma:monit:setup", "puma:monit:enable"
|
10
|
-
after "puma:monit:enable", "monit:reload"
|
11
|
-
|
12
|
-
before "puma:monit.disable", "puma:monit:unmonitor"
|
13
|
-
after "puma:monit:disable", "monit:reload"
|
14
|
-
|
15
|
-
# start service after update in case it has not been stopped
|
16
|
-
# after "deploy:update", "puma:monit:start"
|
17
|
-
# Not needed?
|
18
|
-
|
19
|
-
namespace :puma do
|
20
|
-
namespace :monit do
|
21
|
-
desc "Setup Puma monit-service"
|
22
|
-
task :setup, :roles => [:app, :web, :db] do
|
23
|
-
# Upload configuration
|
24
|
-
Capistrano::BaseHelper::generate_and_upload_config(puma_local_monit_config, File.join(fetch(:monit_available_path), "#{fetch(:puma_runit_service_name)}.conf"))
|
25
|
-
# Enable monitor
|
26
|
-
end
|
27
|
-
|
28
|
-
desc "Enable monit services for Puma"
|
29
|
-
task :enable, :roles => [:app, :web, :db] do
|
30
|
-
Capistrano::MonitBase::Service.enable("#{fetch(:puma_runit_service_name)}.conf")
|
31
|
-
end
|
32
|
-
|
33
|
-
desc "Disable and stop monit services for Puma"
|
34
|
-
task :disable, :roles => [:app, :web, :db] do
|
35
|
-
Capistrano::MonitBase::Service.disable("#{fetch(:puma_runit_service_name)}.conf")
|
36
|
-
end
|
37
|
-
|
38
|
-
desc "Start monit services for Puma (will also try to start the service)"
|
39
|
-
task :start, :roles => [:app, :web, :db] do
|
40
|
-
Capistrano::MonitBase::Service.command_monit("start", fetch(:puma_monit_service_name))
|
41
|
-
end
|
42
|
-
|
43
|
-
desc "Stop monit services for Puma (will also stop the service)"
|
44
|
-
task :stop, :roles => [:app, :web, :db] do
|
45
|
-
Capistrano::MonitBase::Service.command_monit("stop", fetch(:puma_monit_service_name))
|
46
|
-
end
|
47
|
-
|
48
|
-
desc "Restart monit services for Puma"
|
49
|
-
task :restart, :roles => [:app, :web, :db] do
|
50
|
-
Capistrano::MonitBase::Service.command_monit("restart", fetch(:puma_monit_service_name))
|
51
|
-
end
|
52
|
-
|
53
|
-
desc "Monitor Puma"
|
54
|
-
task :monitor, :roles => [:app, :web, :db] do
|
55
|
-
Capistrano::MonitBase::Service.command_monit("monitor", fetch(:puma_monit_service_name))
|
56
|
-
end
|
57
|
-
|
58
|
-
desc "Unmonitor Puma"
|
59
|
-
task :unmonitor, :roles => [:app, :web, :db] do
|
60
|
-
Capistrano::MonitBase::Service.command_monit("unmonitor", fetch(:puma_monit_service_name))
|
61
|
-
end
|
62
|
-
|
63
|
-
desc "Purge Puma monit configuration"
|
64
|
-
task :unmonitor, :roles => [:app, :web, :db], :on_error => :continue do
|
65
|
-
end
|
66
|
-
|
67
|
-
end
|
68
|
-
|
69
|
-
end
|
70
|
-
end
|
@@ -1,128 +0,0 @@
|
|
1
|
-
require 'capistrano/puma/config'
|
2
|
-
require 'capistrano/base_helper/monit_base'
|
3
|
-
|
4
|
-
Capistrano::Configuration.instance.load do
|
5
|
-
|
6
|
-
# Where your nginx lives. Usually /opt/nginx or /usr/local/nginx for source compiled.
|
7
|
-
_cset :nginx_sites_enabled_path, "/etc/nginx/sites-enabled"
|
8
|
-
|
9
|
-
# simple authorization in nginx recipe
|
10
|
-
# Remember NOT to share your deployment file in case you have sensitive passwords stored in it...
|
11
|
-
# This is added to make it easier to deploy staging sites with a simple htpasswd.
|
12
|
-
|
13
|
-
_cset :nginx_use_simple_auth, false
|
14
|
-
_cset :nginx_simple_auth_message, "Restricted site"
|
15
|
-
_cset :nginx_simple_auth_user, "user"
|
16
|
-
_cset :nginx_simple_auth_password, "password"
|
17
|
-
_cset :nginx_simple_auth_salt, (0...8).map{ ('a'..'z').to_a[rand(26)] }.join
|
18
|
-
|
19
|
-
# Server names. Defaults to application name.
|
20
|
-
_cset :server_names, defer {"#{fetch(:application)}_#{Capistrano::BaseHelper.environment}"}
|
21
|
-
|
22
|
-
# Path to the nginx erb template to be parsed before uploading to remote
|
23
|
-
_cset :nginx_local_config, File.join(File.expand_path(File.join(File.dirname(__FILE__),"../../../templates", "nginx", )), "application.conf.erb")
|
24
|
-
|
25
|
-
# Path to where your remote config will reside (I use a directory sites inside conf)
|
26
|
-
_cset :nginx_remote_config, defer {File.join("#{fetch(:shared_path)}", "config", "nginx_#{fetch(:application)}_#{Capistrano::BaseHelper.environment}.conf")}
|
27
|
-
|
28
|
-
# Path to local htpasswd template file
|
29
|
-
_cset :nginx_local_htpasswd, defer {File.join(File.expand_path(File.join(File.dirname(__FILE__),"../../../templates", "nginx", )), "htpasswd.erb")}
|
30
|
-
|
31
|
-
# Path to remote htpasswd file
|
32
|
-
_cset :nginx_remote_htpasswd, defer {File.join("#{fetch(:shared_path)}", "config", ".htpasswd")}
|
33
|
-
|
34
|
-
_cset :nginx_sites_enabled_symlink, defer {File.join(nginx_sites_enabled_path, "#{fetch(:application)}_#{Capistrano::BaseHelper.environment}")}
|
35
|
-
|
36
|
-
_cset :nginx_uses_http, true
|
37
|
-
_cset :nginx_uses_ssl, false
|
38
|
-
_cset :nginx_port, 80
|
39
|
-
|
40
|
-
_cset :nginx_log_path, File.join("/var", "log", "nginx", "#{fetch(:application)}")
|
41
|
-
|
42
|
-
_cset :nginx_client_max_body_size, "10M"
|
43
|
-
|
44
|
-
_cset :nginx_ssl_port, 443
|
45
|
-
_cset :nginx_ssl_use_simple_auth, false
|
46
|
-
_cset :nginx_ssl_client_max_body_size, "10M"
|
47
|
-
_cset :nginx_ssl_public_crt, File.join("/etc", "certs", "server.crt")
|
48
|
-
_cset :nginx_ssl_private_key, File.join("/etc", "certs", "server.key")
|
49
|
-
|
50
|
-
# Nginx tasks are not *nix agnostic, they assume you're using Debian/Ubuntu.
|
51
|
-
# Override them as needed.
|
52
|
-
namespace :puma do
|
53
|
-
namespace :nginx do
|
54
|
-
desc "Parses and uploads nginx configuration for this app."
|
55
|
-
task :setup, :roles => :app , :except => { :no_release => true } do
|
56
|
-
|
57
|
-
Capistrano::BaseHelper.generate_and_upload_config(fetch(:nginx_local_config), fetch(:nginx_remote_config))
|
58
|
-
|
59
|
-
# if auth is enabled, upload htpasswd file
|
60
|
-
# Since passwords are stored in plaintext in the deployment file, you should use simple auth with care.
|
61
|
-
# It is generally better to implement a full authorization stack like oauth, use devise on rails, or other login/auth system
|
62
|
-
if fetch(:nginx_use_simple_auth) or fetch(:nginx_ssl_use_simple_auth)
|
63
|
-
if Capistrano::CLI.ui.agree("Create .htpasswd configuration file? [Yn]")
|
64
|
-
Capistrano::BaseHelper.generate_and_upload_config(fetch(:nginx_local_htpasswd), fetch(:nginx_remote_htpasswd))
|
65
|
-
else
|
66
|
-
set :nginx_use_simple_auth, false
|
67
|
-
set :nginx_ssl_use_simple_auth, false
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
# create log path, must sudo since path can have root-only permissions
|
72
|
-
run "#{sudo} mkdir -p /var/log/nginx/#{fetch(:application)} && #{sudo} chown root:www-data /var/log/nginx/#{fetch(:application)}"
|
73
|
-
end
|
74
|
-
|
75
|
-
desc "Enable nginx site for the application"
|
76
|
-
task :enable, :roles => :app , :except => { :no_release => true } do
|
77
|
-
# symlink to nginx site configuration file
|
78
|
-
run("[ -h #{fetch(:nginx_sites_enabled_symlink)} ] || #{sudo} ln -sf #{fetch(:nginx_remote_config)} #{fetch(:nginx_sites_enabled_symlink)}")
|
79
|
-
end
|
80
|
-
|
81
|
-
desc "Disable nginx site for the application"
|
82
|
-
task :disable, :roles => :app , :except => { :no_release => true } do
|
83
|
-
run("[ ! -h #{fetch(:nginx_sites_enabled_symlink)} ] || #{sudo} rm -f #{fetch(:nginx_sites_enabled_symlink)}")
|
84
|
-
end
|
85
|
-
|
86
|
-
desc "Purge nginx site config for the application"
|
87
|
-
task :purge, :roles => :app , :except => { :no_release => true } do
|
88
|
-
run("[ ! -h #{fetch(:nginx_sites_enabled_symlink)} ] || #{sudo} rm -f #{fetch(:nginx_sites_enabled_symlink)}")
|
89
|
-
# must restart nginx to make sure site is disabled when config is purge
|
90
|
-
run "#{sudo} service nginx restart"
|
91
|
-
run "rm -f #{fetch(:nginx_remote_htpasswd)} && rm -f #{fetch(:nginx_remote_config)}"
|
92
|
-
end
|
93
|
-
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
namespace :nginx do
|
98
|
-
desc "Restart nginx"
|
99
|
-
task :restart, :roles => :app , :except => { :no_release => true } do
|
100
|
-
run "#{sudo} service nginx restart"
|
101
|
-
end
|
102
|
-
|
103
|
-
desc "Stop nginx"
|
104
|
-
task :stop, :roles => :app , :except => { :no_release => true } do
|
105
|
-
run "#{sudo} service nginx stop"
|
106
|
-
end
|
107
|
-
|
108
|
-
desc "Start nginx"
|
109
|
-
task :start, :roles => :app , :except => { :no_release => true } do
|
110
|
-
run "#{sudo} service nginx start"
|
111
|
-
end
|
112
|
-
|
113
|
-
desc "Show nginx status"
|
114
|
-
task :status, :roles => :app , :except => { :no_release => true } do
|
115
|
-
run "#{sudo} service nginx status"
|
116
|
-
end
|
117
|
-
|
118
|
-
end
|
119
|
-
|
120
|
-
after 'deploy:setup' do
|
121
|
-
puma.nginx.setup if Capistrano::CLI.ui.agree("Create nginx configuration file? [Yn]")
|
122
|
-
if Capistrano::CLI.ui.agree("Enable site in nginx? [Yn]")
|
123
|
-
puma.nginx.enable
|
124
|
-
nginx.restart # must restart after enable for nginx to pickup new site
|
125
|
-
end
|
126
|
-
end
|
127
|
-
|
128
|
-
end
|
@@ -1,145 +0,0 @@
|
|
1
|
-
# Puma - Runit
|
2
|
-
require 'capistrano/puma/config'
|
3
|
-
require 'capistrano/base_helper/runit_base'
|
4
|
-
|
5
|
-
Capistrano::Configuration.instance(true).load do
|
6
|
-
after "deploy:setup", "puma:runit:setup"
|
7
|
-
|
8
|
-
# enable service after update in case it has not been setup or is disabled
|
9
|
-
# Service should probably be started as well?
|
10
|
-
after "deploy:update", "puma:runit:enable"
|
11
|
-
before "puma:runit:setup", "puma:flush_sockets"
|
12
|
-
before "puma:runit:setup", "puma:setup"
|
13
|
-
before "puma:runit:quit", "puma:runit:stop"
|
14
|
-
|
15
|
-
namespace :puma do
|
16
|
-
|
17
|
-
desc "Setup Puma configuration"
|
18
|
-
task :setup, :roles => :app do
|
19
|
-
Capistrano::BaseHelper.prepare_path(File.join(fetch(:shared_path), "sockets"), fetch(:user), fetch(:group))
|
20
|
-
|
21
|
-
# Create puma configuration file
|
22
|
-
Capistrano::BaseHelper::generate_and_upload_config(fetch(:puma_local_config), fetch(:puma_remote_config))
|
23
|
-
end
|
24
|
-
|
25
|
-
desc "Flush Puma sockets, as they can end up 'hanging around'"
|
26
|
-
task :flush_sockets, :roles => :app do
|
27
|
-
run "rm -f #{fetch(:puma_socket_file)}; rm -f #{fetch(:puma_control_file)}"
|
28
|
-
end
|
29
|
-
|
30
|
-
namespace :runit do
|
31
|
-
desc "Setup Puma runit-service"
|
32
|
-
task :setup, :roles => :app do
|
33
|
-
|
34
|
-
|
35
|
-
# Create runit config
|
36
|
-
Capistrano::RunitBase.create_service_dir(puma_runit_service_name)
|
37
|
-
Capistrano::BaseHelper::generate_and_upload_config(puma_runit_local_run, Capistrano::RunitBase.remote_run_config_path(puma_runit_service_name))
|
38
|
-
Capistrano::BaseHelper::generate_and_upload_config(puma_runit_local_finish, Capistrano::RunitBase.remote_finish_config_path(puma_runit_service_name))
|
39
|
-
|
40
|
-
#must use quit script for stop as well
|
41
|
-
Capistrano::BaseHelper::generate_and_upload_config(puma_runit_control_q, Capistrano::RunitBase.remote_control_path(puma_runit_service_name, "q"))
|
42
|
-
Capistrano::BaseHelper::generate_and_upload_config(puma_runit_control_q, Capistrano::RunitBase.remote_control_path(puma_runit_service_name, "s"))
|
43
|
-
Capistrano::BaseHelper::generate_and_upload_config(puma_runit_local_log_run, Capistrano::RunitBase.remote_service_log_run_path(puma_runit_service_name))
|
44
|
-
|
45
|
-
# Make scripts executable
|
46
|
-
Capistrano::RunitBase.make_service_scripts_executeable(puma_runit_service_name)
|
47
|
-
# Set correct permissions/owner on log path
|
48
|
-
Capistrano::RunitBase.create_and_permissions_on_path(fetch(:puma_log_path))
|
49
|
-
end
|
50
|
-
|
51
|
-
desc "Enable Puma runit-service"
|
52
|
-
task :enable, :roles => :app do
|
53
|
-
Capistrano::RunitBase.enable_service(puma_runit_service_name)
|
54
|
-
end
|
55
|
-
|
56
|
-
desc "Disable Puma runit-service"
|
57
|
-
task :disable, :roles => :app do
|
58
|
-
Capistrano::RunitBase.disable_service(puma_runit_service_name)
|
59
|
-
end
|
60
|
-
|
61
|
-
desc "Start Puma runit-service"
|
62
|
-
task :start, :roles => :app do
|
63
|
-
Capistrano::RunitBase.start_service(puma_runit_service_name)
|
64
|
-
end
|
65
|
-
|
66
|
-
desc "Start Puma runit-service only ONCE (no supervision...)"
|
67
|
-
task :once, :roles => :app do
|
68
|
-
Capistrano::RunitBase.start_service_once(puma_runit_service_name)
|
69
|
-
end
|
70
|
-
|
71
|
-
desc "Stop Puma runit-service"
|
72
|
-
task :stop, :roles => :app, :on_error => :continue do
|
73
|
-
# have to use force-stop on failed stop, since puma might not terminate properly
|
74
|
-
# will wait 25 seconds for puma to shut down, to allow it to serve any on-going requests
|
75
|
-
Capistrano::RunitBase.control_service(puma_runit_service_name, "force-stop", false, "-w 25")
|
76
|
-
end
|
77
|
-
|
78
|
-
desc "Quit the puma runit-service"
|
79
|
-
task :quit, :roles => :app, :on_error => :continue do
|
80
|
-
Capistrano::RunitBase.control_service(puma_runit_service_name, "quit")
|
81
|
-
end
|
82
|
-
|
83
|
-
desc "Restart Puma runit-service"
|
84
|
-
task :restart, :roles => :app do
|
85
|
-
result = nil
|
86
|
-
started = false
|
87
|
-
|
88
|
-
# It is not possible to see if a restart is in progress using the pumactl tool as of now.
|
89
|
-
|
90
|
-
# restarting = false
|
91
|
-
# # check if puma is already performing a restart
|
92
|
-
# invoke_command("cd #{fetch(:current_path)}; [[ $(#{fetch(:puma_control)} -S #{fetch(:puma_state_file)} status) == *restart* ]] && echo 'restarting';true") do |ch, stream, out|
|
93
|
-
# result = (/restart/ =~ out)
|
94
|
-
# end
|
95
|
-
# restarting = true unless result.nil?
|
96
|
-
# result = nil
|
97
|
-
|
98
|
-
# if restarting == false
|
99
|
-
# check if it is running
|
100
|
-
invoke_command("cd #{fetch(:current_path)}; [[ $(#{fetch(:puma_control)} -S #{fetch(:puma_state_file)} status) == *started* ]] && echo 'started';true") do |ch, stream, out|
|
101
|
-
result = (/started/ =~ out)
|
102
|
-
end
|
103
|
-
started = true unless result.nil?
|
104
|
-
|
105
|
-
if started == true
|
106
|
-
logger.info("\nRestarting puma")
|
107
|
-
# Send USR2 to puma in order to restart it....
|
108
|
-
Capistrano::RunitBase.control_service(puma_runit_service_name, "2")
|
109
|
-
else
|
110
|
-
logger.important("\nStarting puma, (wasn't running before)")
|
111
|
-
Capistrano::RunitBase.start_service(puma_runit_service_name)
|
112
|
-
end
|
113
|
-
# end
|
114
|
-
end
|
115
|
-
|
116
|
-
desc "Phased Restart of Puma"
|
117
|
-
task :phased_restart, :roles => :app do
|
118
|
-
result = nil
|
119
|
-
started = false
|
120
|
-
|
121
|
-
# check if it is running
|
122
|
-
invoke_command("cd #{fetch(:current_path)}; [[ $(#{fetch(:puma_control)} -S #{fetch(:puma_state_file)} status) == *started* ]] && echo 'started';true") do |ch, stream, out|
|
123
|
-
result = (/started/ =~ out)
|
124
|
-
end
|
125
|
-
started = true unless result.nil?
|
126
|
-
|
127
|
-
if started == true
|
128
|
-
# Send USR1 to puma in order to restart it....
|
129
|
-
logger.info("\nPhased restart of puma")
|
130
|
-
Capistrano::RunitBase.control_service(puma_runit_service_name, "1")
|
131
|
-
else
|
132
|
-
logger.important("\nStarting puma, (wasn't running before)")
|
133
|
-
Capistrano::RunitBase.start_service(puma_runit_service_name)
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
|
-
desc "Purge Puma runit configuration"
|
138
|
-
task :purge, :roles => :app, :on_error => :continue do
|
139
|
-
Capistrano::RunitBase.force_control_service(puma_runit_service_name, "force-stop", true)
|
140
|
-
Capistrano::RunitBase.purge_service(puma_runit_service_name)
|
141
|
-
end
|
142
|
-
|
143
|
-
end
|
144
|
-
end
|
145
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
# Puma configuration for: <% c = Capistrano::BaseHelper::get_capistrano_instance %>
|
2
|
-
# <%= "#{c.fetch(:application)} running as #{c.fetch(:user)} in environment #{Capistrano::BaseHelper.environment}" %>
|
3
|
-
workers <%= c.fetch(:puma_workers) %>
|
4
|
-
threads <%= c.fetch(:puma_min_threads) %>, <%= c.fetch(:puma_max_threads) %>
|
5
|
-
bind '<%= c.fetch(:puma_socket_url) %>'
|
6
|
-
pidfile '<%= c.fetch(:puma_pid_file) %>'
|
7
|
-
state_path '<%= c.fetch(:puma_state_file) %>'
|
8
|
-
environment '<%= "#{Capistrano::BaseHelper.environment}" %>'
|
9
|
-
<%= "activate_control_app '#{c.fetch(:puma_control_url)}'" if c.fetch(:puma_activate_control_app) %>
|
10
|
-
|
11
|
-
# In some cases preloading the app is best to avoid some infinite restart loops, however, it cannot be used in
|
12
|
-
# combination with phased restart.
|
13
|
-
<%= "preload_app!" if c.fetch(:puma_use_preload_app) %>
|
14
|
-
|
15
|
-
directory '<%= File.join(c.fetch(:deploy_to), "current") %>'
|
16
|
-
|
17
|
-
# TODO - fix restart block!
|
18
|
-
# <%= "on_restart do" if c.fetch(:puma_on_restart_active) %>
|
19
|
-
# <%= " puts \"Restarting puma\"" if c.fetch(:puma_on_restart_active) %>
|
20
|
-
# <%= "end" if c.fetch(:puma_on_restart_active) %>
|
@@ -1,8 +0,0 @@
|
|
1
|
-
#!/bin/bash --login
|
2
|
-
<% c = Capistrano::BaseHelper.get_capistrano_instance %>
|
3
|
-
# Announcing stop/abort
|
4
|
-
echo "<%= "User: #{c.fetch(:user)} Application: #{c.fetch(:application)} Service: #{c.fetch(:puma_runit_service_name)}" %> stopping..."
|
5
|
-
|
6
|
-
# The command used when puma is asked to quit/stop/exit, overridden here, as runit normal signal will not work with puma
|
7
|
-
cd '<%= c.current_path %>'
|
8
|
-
RAILS_ENV=<%= Capistrano::BaseHelper.environment %> exec <%= c.fetch(:puma_control) %> -S <%= c.fetch(:puma_state_file) %> stop
|
data/templates/runit/log-run.erb
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
#!/bin/sh -e
|
2
|
-
<% c = Capistrano::BaseHelper::get_capistrano_instance %>
|
3
|
-
# Log output for puma running on <%= c.fetch(:application) %> running as <%= c.fetch(:user) %>
|
4
|
-
# make sure the log directory exists
|
5
|
-
mkdir -p "<%= c.fetch(:puma_log_path) %>"
|
6
|
-
# change path to the log directory
|
7
|
-
cd "<%= c.fetch(:puma_log_path) %>"
|
8
|
-
# start logging
|
9
|
-
# exec chpst -u syslog svlogd -tt "<%= c.fetch(:puma_log_path) %>"
|
10
|
-
exec svlogd -tt "<%= c.fetch(:puma_log_path) %>"
|