← Back to Upcase

Puma and Capistrano


(Shankar Dhanasekaran) #1

Being new to capistrano and rails deployment, I have managed to produce the below deploy.rb (thanks to Google). Can someone familar with capistrano and puma guide me on any missing pieces in the code below? (btw, after I deploy, I get “Invalid auth token” error on my production site)

require "bundler/capistrano"

server "ip.add.re.ss", :web, :app, :db, primary: true

set :application, "myapp"
set :user, "myapp"
set :deploy_to, "/home/#{user}/apps/#{application}"
set :deploy_via, :remote_cache
set :use_sudo, false

set :scm, "git"
set :repository, "git@mygitlab.com:root/mm.git"
set :branch, "master"

default_run_options[:pty] = true
ssh_options[:forward_agent] = true

after "deploy", "deploy:cleanup"

## Puma config ##
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

If any of the thoughtbot ninja can share some code on deploy.rb using puma, it will be much helpful.

Thanks