Skip to content

Instantly share code, notes, and snippets.

@tanihiro
Last active June 3, 2016 05:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tanihiro/6060400 to your computer and use it in GitHub Desktop.
Save tanihiro/6060400 to your computer and use it in GitHub Desktop.
capistranoの設定ファイル
require "capistrano/ext/multistage"
require 'capistrano_colors'
require "bundler/capistrano"
set :stages, %w(production staging)
set :default_stage, "staging"
set :repository, "Repository URL"
set :scm, :subversion
set :scm_username, "svn_username"
set :scm_password, "svn_password"
# set :scm, :git # You can set :scm explicitly or Capistrano will make an intelligent guess based on known version control directory names
# Or: `accurev`, `bzr`, `cvs`, `darcs`, `git`, `mercurial`, `perforce`, `subversion` or `none`
set :user, 'username'
set :password, 'password'
set :use_sudo, false
set :keep_releases, 5
set :deploy_via, :rsync_with_remote_cache
set :copy_exclude, %W(
.svn
**/.svn
.git
**/.git
.bundle/
.gitignore
.ruby-version
)
set :rsync_options, '-rtlvz --delete --delete-excluded ' +
copy_exclude.map{|e| "--exclude='#{e}'"}.join(' ')
# if you want to clean up old releases on each deploy uncomment this:
# if you're still using the script/reaper helper you will need
# these http://github.com/rails/irs_process_scripts
# If you are using Passenger mod_rails uncomment this:
namespace :deploy do
task :default do
update
end
task :update do
transaction do
update_code
create_config_symlink
create_symlink
end
end
task :start do
run "cd #{current_path} && bundle exec unicorn_rails -c #{current_path}/config/unicorn.rb -E #{rails_env} -D"
end
task :restart do
stop
start
end
task :reload do
if File.exist? "#{current_path}/tmp/pids/unicorn.pid"
run "kill -s USR2 `cat #{current_path}/tmp/pids/unicorn.pid`"
else
start
end
end
task :stop do
run "kill -s QUIT `cat #{current_path}/tmp/pids/unicorn.pid`"
end
task :cache_clear do
run "cd #{current_path} && RAILS_ENV=#{rails_env} bundle exec rake tmp:cache:clear"
end
task :precompile, :roles => :web do
run "cd #{current_path} && RAILS_ENV=#{rails_env} bundle exec rake assets:precompile"
end
task :create_config_symlink, :roles => :web do
on_rollback { run "rm -rf #{release_path}; true" }
run "cp #{release_path}/config/database.yml.base #{shared_path}/database.yml && ln -s #{shared_path}/database.yml #{release_path}/config/database.yml"
run "cp #{release_path}/config/unicorn/#{rails_env}.rb #{shared_path}/unicorn.rb && ln -s #{shared_path}/unicorn.rb #{release_path}/config/unicorn.rb"
end
end
after "deploy", "deploy:cleanup"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment