Last active
March 12, 2019 14:02
-
-
Save cesc1989/582911330dfbfb6e6df4 to your computer and use it in GitHub Desktop.
Deploy with capistrano
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Change these | |
set :repo_url, '[ENTER YOUR GIT REPO URL HERE]' | |
set :user, 'macsa' | |
set :branch, 'test' | |
set :application, 'staging' | |
set :puma_threads, [4, 16] | |
set :puma_workers, 0 | |
# Don't change these unless you know what you're doing | |
set :pty, false | |
set :use_sudo, false | |
set :deploy_via, :remote_cache | |
set :deploy_to, "/home/#{fetch(:user)}/apps/#{fetch(:application)}" | |
set :puma_bind, "unix://#{shared_path}/tmp/sockets/#{fetch(:application)}-puma.sock" | |
set :puma_default_control_app, "unix://#{shared_path}/tmp/sockets/#{fetch(:application)}-puma-ctl.sock" | |
set :puma_state, "#{shared_path}/tmp/pids/puma.state" | |
set :puma_pid, "#{shared_path}/tmp/pids/puma.pid" | |
set :puma_access_log, "#{release_path}/log/puma.error.log" | |
set :puma_error_log, "#{release_path}/log/puma.access.log" | |
set :puma_preload_app, true | |
set :puma_worker_timeout, nil | |
set :puma_init_active_record, true # Change to false when not using ActiveRecord | |
set :sidekiq_pid, "#{shared_path}/tmp/pids/sidekiq.pid" | |
set :sidekiq_log, "#{release_path}/log/sidekiq.log" | |
set :ssh_options, { | |
forward_agent: true, | |
user: fetch(:user), | |
keys: %w(~/.ssh/id_rsa.pub), | |
password: '[ENTER YOUR PASSWORD HERE]]' | |
} | |
namespace :puma do | |
desc 'Create Directories for Puma Pids and Socket' | |
task :make_dirs do | |
on roles(:app) do | |
execute "mkdir #{shared_path}/tmp/sockets -p" | |
execute "mkdir #{shared_path}/tmp/pids -p" | |
end | |
end | |
before :start, :make_dirs | |
end | |
namespace :deploy do | |
desc "Make sure local git is in sync with remote." | |
task :check_revision do | |
on roles(:app) do | |
unless `git rev-parse HEAD` == `git rev-parse origin/#{fetch(:branch)}` | |
puts "WARNING: HEAD is not the same as origin/#{fetch(:branch)}" | |
puts "Run `git push` to sync changes." | |
exit | |
end | |
end | |
end | |
desc 'Initial Deploy' | |
task :initial do | |
on roles(:app) do | |
before 'deploy:restart', 'puma:start' | |
invoke 'deploy' | |
end | |
end | |
desc 'Restart application' | |
task :restart do | |
on roles(:app), in: :sequence, wait: 5 do | |
invoke 'puma:restart' | |
end | |
end | |
before :starting, :check_revision | |
after :finishing, :compile_assets | |
after :finishing, :cleanup | |
after :finishing, :restart | |
end | |
# ps aux | grep puma # Get puma pid | |
# kill -s SIGUSR2 pid # Restart puma | |
# kill -s SIGTERM pid # Stop puma |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Change these | |
set :repo_url, '[ENTER YOUR GIT REPO URL HERE]' | |
set :user, 'macsa' | |
set :branch, 'test' | |
set :application, 'staging' | |
set :puma_threads, [4, 16] | |
set :puma_workers, 0 | |
# Don't change these unless you know what you're doing | |
set :pty, false | |
set :use_sudo, false | |
set :deploy_via, :remote_cache | |
set :deploy_to, "/home/#{fetch(:user)}/apps/#{fetch(:application)}" | |
set :puma_bind, "unix://#{shared_path}/tmp/sockets/#{fetch(:application)}-puma.sock" | |
set :puma_default_control_app, "unix://#{shared_path}/tmp/sockets/#{fetch(:application)}-puma-ctl.sock" | |
set :puma_state, "#{shared_path}/tmp/pids/puma.state" | |
set :puma_pid, "#{shared_path}/tmp/pids/puma.pid" | |
set :puma_access_log, "#{release_path}/log/puma.access.log" | |
set :puma_error_log, "#{release_path}/log/puma.error.log" | |
set :puma_preload_app, true | |
set :puma_worker_timeout, nil | |
set :puma_init_active_record, true # Change to false when not using ActiveRecord | |
set :sidekiq_pid, "#{shared_path}/tmp/pids/sidekiq.pid" | |
set :sidekiq_log, "#{release_path}/log/sidekiq.log" | |
set :ssh_options, { | |
forward_agent: true, | |
user: fetch(:user), | |
keys: %w(~/.ssh/id_rsa.pub), | |
password: '[ENTER YOUR PASSWORD HERE]' | |
} | |
namespace :puma do | |
desc "Start the application" | |
task :start_app do | |
on roles(:app) do | |
execute "cd #{current_path} RAILS_ENV=#{fetch(:stage)} /usr/local/rvm/bin/rvm default do bundle exec pumactl -b -d 'unix://#{shared_path}/tmp/sockets/#{fetch(:application)}-puma.sock' -S #{shared_path}/tmp/pids/#{fetch(:application)}-puma.state --control 'unix://#{shared_path}/tmp/sockets/#{fetch(:application)}-puma-ctl.sock'" | |
end | |
end | |
desc 'Create Directories for Puma Pids and Socket' | |
task :make_dirs do | |
on roles(:app) do | |
execute "mkdir #{shared_path}/tmp/sockets -p" | |
execute "mkdir #{shared_path}/tmp/pids -p" | |
end | |
end | |
before :start, :make_dirs | |
after "deploy:starting", :start_app | |
end | |
namespace :deploy do | |
desc "Make sure local git is in sync with remote." | |
task :check_revision do | |
on roles(:app) do | |
unless `git rev-parse HEAD` == `git rev-parse origin/#{fetch(:branch)}` | |
puts "WARNING: HEAD is not the same as origin/#{fetch(:branch)}" | |
puts "Run `git push` to sync changes." | |
exit | |
end | |
end | |
end | |
desc 'Set config/puma.rb-symlink for upstart' | |
task :puma_config do | |
on roles(:app) do | |
execute "ln -s #{shared_path}/puma.rb #{fetch(:deploy_to)}/current/config/puma.rb" | |
end | |
end | |
desc 'Initial Deploy' | |
task :initial do | |
on roles(:app) do | |
before 'deploy:restart', 'puma:start' | |
invoke 'deploy' | |
end | |
end | |
desc 'Restart application' | |
task :restart do | |
on roles(:app), in: :sequence, wait: 5 do | |
invoke 'puma:restart' | |
end | |
end | |
before :starting, :check_revision | |
after :finishing, :puma_config | |
after :finishing, :compile_assets | |
after :finishing, :cleanup | |
after :finishing, :restart | |
end | |
## Commands | |
## cap staging deploy:initial | |
## cap staging puma:start |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Change these | |
set :repo_url, '[ENTER YOUR GIT REPO URL HERE]' | |
set :user, 'macsa' | |
set :branch, 'test' | |
set :application, 'staging' | |
# Don't change these unless you know what you're doing | |
set :pty, false | |
set :use_sudo, true | |
set :deploy_via, :remote_cache | |
set :deploy_to, "/home/#{fetch(:user)}/apps/#{fetch(:application)}" | |
set :sidekiq_pid, "#{shared_path}/tmp/pids/sidekiq.pid" | |
set :sidekiq_log, "#{release_path}/log/sidekiq.log" | |
set :whenever_identifier, ->{ "#{fetch(:application)}_#{fetch(:stage)}" } | |
set :ssh_options, { | |
forward_agent: false, | |
user: fetch(:user), | |
keys: %w(~/.ssh/id_rsa.pub), | |
password: '[ENTER YOUR PASSWORD HERE]' | |
} | |
set :passenger_restart_with_sudo, true | |
namespace :deploy do | |
desc "Make sure local git is in sync with remote." | |
task :check_revision do | |
on roles(:app) do | |
unless `git rev-parse HEAD` == `git rev-parse origin/#{fetch(:branch)}` | |
puts "WARNING: HEAD is not the same as origin/#{fetch(:branch)}" | |
puts "Run `git push` to sync changes." | |
exit | |
end | |
end | |
end | |
desc 'Create shared upload folder' | |
task :symlink_uploads do | |
on roles(:app) do | |
execute "mkdir #{shared_path}/uploads -p" | |
execute "ln -nfs #{shared_path}/uploads #{release_path}/public/uploads" | |
end | |
end | |
desc 'Initial Deploy' | |
task :initial do | |
on roles(:app) do | |
invoke 'deploy' | |
end | |
end | |
before :starting, :check_revision | |
after :finishing, :compile_assets | |
after :finishing, :cleanup | |
after :finishing, :restart | |
after :finishing, :symlink_uploads | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ojo con la gema de capistrano y puma. Tiene que ser capistrano3-puma no capistrano-puma. Si está, borrarla:
gem list capistrano-puma
Si está:
gem uninstall capistrano-puma
y luego:
bundle update