Skip to content

Instantly share code, notes, and snippets.

@owainlewis
Last active January 2, 2016 05:49
Show Gist options
  • Select an option

  • Save owainlewis/8259335 to your computer and use it in GitHub Desktop.

Select an option

Save owainlewis/8259335 to your computer and use it in GitHub Desktop.
Capistrano config for client site
set :application, ''
set :repo_url, 'git@yoursite.git'
set :deploy_to, '/var/www/sitename'
set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}
set :keep_releases, 5
set :sudo, true
set :rbenv_type, :user
set :rbenv_ruby, '2.0.0-p353'
set :default_environment, {
'PATH' => "/home/deploy/.rbenv/shims:/home/deploy/.rbenv/bin:$PATH"
}
SSHKit.config.command_map[:rake] = "bundle exec rake"
SSHKit.config.command_map[:rails] = "bundle exec rails"
namespace :unicorn do
task :start do
on roles(:app, :web) do
execute "sudo service unicorn start"
end
end
task :stop do
on roles(:app, :web) do
execute "sudo service unicorn stop"
end
end
end
namespace :debug do
desc "tail production log files"
task :logs do
on roles(:app, :web) do
trap("INT") { puts 'Interupted'; exit 0; }
execute "tail -f #{shared_path}/log/production.log" do |channel, stream, data|
puts # for an extra line break before the host name
puts "#{channel[:host]}: #{data}"
break if stream == :err
end
end
end
desc "tail unicorn log files"
task :unicorn_log do
on roles(:app, :web) do
trap("INT") { puts 'Interupted'; exit 0; }
execute "tail -f #{shared_path}/log/unicorn.stderr.log" do |channel, stream, data|
puts # for an extra line break before the host name
puts "#{channel[:host]}: #{data}"
break if stream == :err
end
end
end
end
namespace :maintenance do
task :disable do
on roles(:app, :web), in: :sequence, wait: 5 do
execute "mv #{ release_path }/public/maintenance.html #{ release_path }/public/maintenance-page.html"
end
end
task :enable do
on roles(:app, :web), in: :sequence, wait: 5 do
execute "mv #{ release_path }/public/maintenance-page.html #{ release_path }/public/maintenance.html"
end
end
end
namespace :deploy do
desc 'Restart application'
task :restart do
on roles(:app, :web), in: :sequence, wait: 5 do
execute "sudo service unicorn restart"
end
end
after :finishing, 'deploy:cleanup'
end
@owainlewis
Copy link
Author

Using new Capistrano 3 gem

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