mirror of
https://github.com/puma/puma.git
synced 2022-11-09 13:48:40 -05:00
Add phased restart to capistrano recipe.
Add phased restart task. Little refactor. Do not use fetch when no needed.
This commit is contained in:
parent
0ded7fbbdd
commit
44cbda1c9b
2 changed files with 19 additions and 11 deletions
|
@ -212,6 +212,7 @@ and then
|
||||||
$ bundle exec cap puma:start
|
$ bundle exec cap puma:start
|
||||||
$ bundle exec cap puma:restart
|
$ bundle exec cap puma:restart
|
||||||
$ bundle exec cap puma:stop
|
$ bundle exec cap puma:stop
|
||||||
|
$ bundle exec cap puma:phased_restart
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -8,34 +8,41 @@ Capistrano::Configuration.instance.load do
|
||||||
# v2 but is fixed in v3.
|
# v2 but is fixed in v3.
|
||||||
shared_children.push('tmp/sockets')
|
shared_children.push('tmp/sockets')
|
||||||
|
|
||||||
_cset(:puma_cmd) { "#{fetch(:bundle_cmd, 'bundle')} exec puma" }
|
_cset(:puma_cmd) { "#{fetch(:bundle_cmd, 'bundle')} exec puma" }
|
||||||
_cset(:pumactl_cmd) { "#{fetch(:bundle_cmd, 'bundle')} exec pumactl" }
|
_cset(:pumactl_cmd) { "#{fetch(:bundle_cmd, 'bundle')} exec pumactl" }
|
||||||
_cset(:puma_state) { "#{shared_path}/sockets/puma.state" }
|
_cset(:puma_env) { fetch(:rack_env, fetch(:rails_env, 'production')) }
|
||||||
|
_cset(:puma_state) { "#{shared_path}/sockets/puma.state" }
|
||||||
_cset(:puma_socket) { "unix://#{shared_path}/sockets/puma.sock" }
|
_cset(:puma_socket) { "unix://#{shared_path}/sockets/puma.sock" }
|
||||||
_cset(:puma_role) { :app }
|
_cset(:puma_role) { :app }
|
||||||
|
|
||||||
namespace :puma do
|
namespace :puma do
|
||||||
desc 'Start puma'
|
desc 'Start puma'
|
||||||
task :start, :roles => lambda { fetch(:puma_role) }, :on_no_matching_servers => :continue do
|
task :start, :roles => lambda { puma_role }, :on_no_matching_servers => :continue do
|
||||||
run "cd #{current_path} && #{fetch(:puma_cmd)} #{start_options}", :pty => false
|
run "cd #{current_path} && #{puma_cmd} #{start_options}", :pty => false
|
||||||
end
|
end
|
||||||
|
|
||||||
desc 'Stop puma'
|
desc 'Stop puma'
|
||||||
task :stop, :roles => lambda { fetch(:puma_role) }, :on_no_matching_servers => :continue do
|
task :stop, :roles => lambda { puma_role }, :on_no_matching_servers => :continue do
|
||||||
run "cd #{current_path} && #{fetch(:pumactl_cmd)} -S #{state_path} stop"
|
run "cd #{current_path} && #{pumactl_cmd} -S #{state_path} stop"
|
||||||
end
|
end
|
||||||
|
|
||||||
desc 'Restart puma'
|
desc 'Restart puma'
|
||||||
task :restart, :roles => lambda { fetch(:puma_role) }, :on_no_matching_servers => :continue do
|
task :restart, :roles => lambda { puma_role }, :on_no_matching_servers => :continue do
|
||||||
run "cd #{current_path} && #{fetch(:pumactl_cmd)} -S #{state_path} restart"
|
run "cd #{current_path} && #{pumactl_cmd} -S #{state_path} restart"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
desc 'Restart puma (phased restart)'
|
||||||
|
task :phased_restart, :roles => lambda { puma_role }, :on_no_matching_servers => :continue do
|
||||||
|
run "cd #{current_path} && #{pumactl_cmd} -S #{state_path} phased-restart"
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def start_options
|
def start_options
|
||||||
if config_file
|
if config_file
|
||||||
"-q -d -e #{puma_env} -C #{config_file}"
|
"-q -d -e #{puma_env} -C #{config_file}"
|
||||||
else
|
else
|
||||||
"-q -d -e #{puma_env} -b '#{fetch(:puma_socket)}' -S #{state_path} --control 'unix://#{shared_path}/sockets/pumactl.sock'"
|
"-q -d -e #{puma_env} -b '#{puma_socket}' -S #{state_path} --control 'unix://#{shared_path}/sockets/pumactl.sock'"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -52,7 +59,7 @@ Capistrano::Configuration.instance.load do
|
||||||
end
|
end
|
||||||
|
|
||||||
def state_path
|
def state_path
|
||||||
(config_file ? configuration.options[:state] : nil) || fetch(:puma_state)
|
(config_file ? configuration.options[:state] : nil) || puma_state
|
||||||
end
|
end
|
||||||
|
|
||||||
def configuration
|
def configuration
|
||||||
|
|
Loading…
Reference in a new issue