Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
set :stage, 'production'
set :shared_children, shared_children << 'tmp/sockets'
puma_sock = "unix://#{shared_path}/sockets/puma.sock"
puma_control = "unix://#{shared_path}/sockets/pumactl.sock"
puma_state = "#{shared_path}/sockets/puma.state"
puma_log = "#{shared_path}/log/puma-#{stage}.log"
namespace :deploy do
desc "Start the application"
task :start do
run "cd #{current_path} && RAILS_ENV=#{stage} && bundle exec puma -b '#{puma_sock}' -e #{stage} -t2:4 --control '#{puma_control}' -S #{puma_state} >> #{puma_log} 2>&1 &", :pty => false
end
desc "Stop the application"
task :stop do
run "cd #{current_path} && RAILS_ENV=#{stage} && bundle exec pumactl -S #{puma_state} stop"
end
desc "Restart the application"
task :restart, :roles => :app, :except => { :no_release => true } do
run "cd #{current_path} && RAILS_ENV=#{stage} && bundle exec pumactl -S #{puma_state} restart"
end
desc "Status of the application"
task :status, :roles => :app, :except => { :no_release => true } do
run "cd #{current_path} && RAILS_ENV=#{stage} && bundle exec pumactl -S #{puma_state} stats"
end
end
@ronhornbaker
Copy link

ronhornbaker commented Oct 10, 2016

Thanks for this, came in very handy. With Capistrano 3.6.0, I had to change the command line calls to the format below, and was unable to use the puma_ variables in the four calls.

I also learned the hard way that when performance tuning and fiddling with the thread and worker counts, don't do just a cap production deploy:restart, because you are restarting puma with the previous settings. Instead, do cap production deploy:stop followed by cap production deploy:start.

task :start do
  on roles(:web) do
    within "#{fetch(:deploy_to)}/current/" do
      with RAILS_ENV: fetch(:stage) do
        execute :bundle, :exec, :"puma -b 'unix://#{shared_path}/tmp/sockets/puma.sock' -e #{fetch(:stage)} -t 1:32 -w 2 --control 'unix://#{shared_path}/tmp/sockets/pumactl.sock' -S #{shared_path}/tmp/pids/puma.state >> #{shared_path}/log/puma-#{fetch(:stage)}.log 2>&1 &"
      end
    end
  end
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment