Skip to content

Commit

Permalink
Use SSHKit command_map
Browse files Browse the repository at this point in the history
  • Loading branch information
hbin committed Sep 10, 2015
1 parent 0f31b00 commit 44dd132
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
10 changes: 6 additions & 4 deletions lib/capistrano/tasks/puma.rake
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

namespace :load do
task :defaults do
set :puma_default_hooks, -> { true }
Expand All @@ -23,6 +22,9 @@ namespace :load do
set :rbenv_map_bins, fetch(:rbenv_map_bins).to_a.concat(%w{ puma pumactl })
set :rvm_map_bins, fetch(:rvm_map_bins).to_a.concat(%w{ puma pumactl })

# Bundler integration
set :bundle_bins, fetch(:bundle_bins).to_a.concat(%w( puma pumactl ))

# Nginx and puma configuration
set :nginx_config_name, -> { "#{fetch(:application)}_#{fetch(:stage)}" }
set :nginx_sites_available_path, -> { '/etc/nginx/sites-available' }
Expand Down Expand Up @@ -61,7 +63,7 @@ namespace :puma do
end
within current_path do
with rack_env: fetch(:puma_env) do
execute :bundle, 'exec', :puma, "-C #{fetch(:puma_conf)} --daemon"
execute :puma, "-C #{fetch(:puma_conf)} --daemon"
end
end
end
Expand All @@ -77,7 +79,7 @@ namespace :puma do
with rack_env: fetch(:puma_env) do
if test "[ -f #{fetch(:puma_pid)} ]"
if test "kill -0 $( cat #{fetch(:puma_pid)} )"
execute :bundle, 'exec', :pumactl, "-S #{fetch(:puma_state)} #{command}"
execute :pumactl, "-S #{fetch(:puma_state)} #{command}"
else
# delete invalid pid file , process is not running.
execute :rm, fetch(:puma_pid)
Expand All @@ -102,7 +104,7 @@ namespace :puma do
with rack_env: fetch(:puma_env) do
if test "[ -f #{fetch(:puma_pid)} ]" and test "kill -0 $( cat #{fetch(:puma_pid)} )"
# NOTE pid exist but state file is nonsense, so ignore that case
execute :bundle, 'exec', :pumactl, "-S #{fetch(:puma_state)} #{command}"
execute :pumactl, "-S #{fetch(:puma_state)} #{command}"
else
# Puma is not running or state file is not present : Run it
invoke 'puma:start'
Expand Down
4 changes: 2 additions & 2 deletions lib/capistrano/templates/puma_monit.conf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
#
check process <%= puma_monit_service_name %>
with pidfile "<%= fetch(:puma_pid) %>"
start program = "/usr/bin/sudo -u <%= puma_user(@role) %> /bin/bash -c 'cd <%= current_path %> && <%= SSHKit.config.command_map[:bundle] %> exec puma -C <%= fetch(:puma_conf) %> --daemon'"
stop program = "/usr/bin/sudo -u <%= puma_user(@role) %> /bin/bash -c 'cd <%= current_path %> && <%= SSHKit.config.command_map[:bundle] %> exec pumactl -S <%= fetch(:puma_state) %> stop'"
start program = "/usr/bin/sudo -u <%= puma_user(@role) %> /bin/bash -c 'cd <%= current_path %> && <%= SSHKit.config.command_map[:puma] %> -C <%= fetch(:puma_conf) %> --daemon'"
stop program = "/usr/bin/sudo -u <%= puma_user(@role) %> /bin/bash -c 'cd <%= current_path %> && <%= SSHKit.config.command_map[:pumactl] %> -S <%= fetch(:puma_state) %> stop'"

0 comments on commit 44dd132

Please sign in to comment.