public
Last active

Example Capistrano deploy file

  • Download Gist
deploy.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
require "bundler/capistrano"
 
server "example.com", :web, :app, :db, primary: true
 
set :application, "example"
set :user, "user"
set :deploy_to, "/var/www/#{application}"
set :use_sudo, false
set :keep_releases, 3
 
set :scm, "git"
set :repository, "file:///var/git/#{application}.git"
set :local_repository, "user@example.com:/var/git/#{application}.git"
set :branch, "master"
 
default_run_options[:pty] = true
ssh_options[:forward_agent] = true
 
after "deploy:update_code", "deploy:migrate"
after "deploy", "deploy:cleanup"
 
namespace :deploy do
%w[start stop].each do |command|
desc "#{command} nginx server"
task command, roles: :app, except: {no_release: true} do
sudo "#{try_sudo} service nginx #{command}"
end
end
desc "restart passenger server"
task :restart, roles: :app, except: { no_release: true } do
run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"
end
 
task :setup_config, roles: :app do
sudo "ln -nfs #{current_path}/config/nginx.conf /opt/nginx/conf/nginx.conf"
run "mkdir -p #{shared_path}/config"
put File.read("config/database.yml"), "#{shared_path}/config/database.yml"
run "mkdir -p #{shared_path}/uploads"
puts "==> IMPORTANT!!! Now edit database.yml in #{shared_path}/config <==="
end
after "deploy:setup", "deploy:setup_config"
 
task :symlink_config, roles: :app do
run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
run "rm -rf #{release_path}/public/uploads"
run "ln -nfs #{shared_path}/uploads #{release_path}/public/"
end
after "deploy:finalize_update", "deploy:symlink_config"
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.