Skip to content

Instantly share code, notes, and snippets.

@ryansch
Forked from tompata/Capfile
Created December 8, 2010 00:07
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 ryansch/732671 to your computer and use it in GitHub Desktop.
Save ryansch/732671 to your computer and use it in GitHub Desktop.
load 'deploy' if respond_to?(:namespace) # cap2 differentiator
# Dir['vendor/plugins/*/recipes/*.rb'].each { |plugin| load(plugin) }
load 'config/deploy' # remove this line to skip loading any of the default tasks
after 'deploy:finalize_code', 'deploy:web:disable'
after 'deploy:start', 'deploy:web:enable'
namespace :deploy do
# runs bundle install locally before uploading code
# IMPORTANT: this is important because of precompiling packages
# IMPORTANT: use should run capistrano from a deployment machine, where everything is the SAME like in production (architecture, libs, etc)
before "deploy:update_code" do
puts "Warning: copy_cache dir (#{copy_cache}) doesnt exist!" unless File.exists?( copy_cache )
system( "cd #{copy_cache} && rm -rf vendor/bundle" )
system( "cd #{copy_cache} && bundle install --deployment --without development test spec cucumber" )
end
task :prepare_remote_dir, :roles => :app do
run "mkdir -p #{copy_remote_dir}"
end
before "deploy:update_code", "deploy:prepare_remote_dir"
# cron
task :setup_cronbuilder, :roles => :app do
run "mkdir -p /home/dev/.cronbuilder"
run "mkdir -p /home/dev/bin"
put IO.read( "config/cron/cronbuilder" ), "/home/dev/bin/cronbuilder", :mode => "0700"
end
after "deploy:setup", "deploy:setup_cronbuilder"
task :create_shared_dirs, :roles => :app do
shared_dirs = [
"#{shared_path}/storage/attachment",
"#{shared_path}/storage/solr"
]
run "mkdir -p #{shared_dirs.join(' ')}"
# add group write permissions
run "chmod -R g+w #{shared_dirs.join(' ')}"
run "setfacl -d -m group::rwx #{shared_dirs.join(' ')}"
end
after "deploy:setup", "deploy:create_shared_dirs"
# passenger
task :start, :roles => :app do
run "touch #{current_path}/tmp/restart.txt"
end
task :stop, :roles => :app do
end
task :restart, :roles => :app do
stop
start
end
desc "After update code - generate a Rails project and finalize files"
task :finalize_code, :roles => :app do
# checking remote gems
run "ls #{latest_release}/vendor/bundle/ruby/1.8/gems"
# create special tmp dirs
run "mkdir -p #{latest_release}/tmp"
run "mkdir -p #{latest_release}/tmp/cache"
# add group write permissions to tmp dir
run "chmod -R g+w #{latest_release}/tmp"
run "setfacl -d -m group::rwx #{latest_release}/tmp"
# remove files from public dir
run "cd #{latest_release}/public && rm -f index.html"
# create symlinks
run "mkdir -p #{latest_release}/solr/data"
run "ln -s #{shared_path}/storage/attachment #{latest_release}/public/attachment"
run "ln -s #{shared_path}/storage/solr #{latest_release}/solr/data/#{rails_env}"
end
after "deploy:update_code", "deploy:finalize_code"
# setup cronbuilder
# symlink application level cron file
task :setup_cron, :roles => :app do
run "rm -f /home/dev/.cronbuilder/#{application}" rescue ""
run "ln -s #{latest_release}/config/cron/#{rails_env}.txt /home/dev/.cronbuilder/#{application}"
run "/bin/bash /home/dev/bin/cronbuilder"
end
after "deploy:finalize_code", "deploy:setup_cron"
# daemons
task :app_start, :roles => :app do
run "cd #{current_path} && RAILS_ENV=#{rails_env} ruby script/delayed_job start"
end
before 'deploy:start', 'deploy:app_start'
task :app_stop, :roles => :app do
run "cd #{latest_release} && RAILS_ENV=#{rails_env} ruby script/delayed_job stop" rescue nil
end
after 'deploy:finalize_code', 'deploy:app_stop'
# solr
task :solr_start, :roles => :app do
run "cd #{current_path} && RAILS_ENV=#{rails_env} rake sunspot:solr:start"
end
before 'deploy:start', 'deploy:solr_start'
task :solr_stop, :roles => :app do
run "cd #{latest_release} && RAILS_ENV=#{rails_env} rake sunspot:solr:stop" rescue nil
end
after 'deploy:finalize_code', 'deploy:solr_stop'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment