Skip to content

Instantly share code, notes, and snippets.

@dpaluy
Created September 25, 2012 09:44
Show Gist options
  • Save dpaluy/3780926 to your computer and use it in GitHub Desktop.
Save dpaluy/3780926 to your computer and use it in GitHub Desktop.
Capistrano recipes
#############################################################
# Capistrano recipes
#############################################################
task :uname do
run "uname -a"
end
# Usage: wait_for_process_to_end('delayed_job')
#
def wait_for_process_to_end(process_name)
run "COUNT=1; until [ $COUNT -eq 0 ]; do COUNT=`ps -ef | grep -v 'ps -ef' | grep -v 'grep' | grep -i '#{process_name}'|wc -l` ; echo 'waiting for #{process_name} to end' ; sleep 2 ; done"
end
namespace :db do
desc 'Dumps the production database to db/production_data.sql on the remote server'
task :remote_db_dump, :roles => :db, :only => { :primary => true } do
run "cd #{deploy_to}/#{current_dir} && " +
"rake RAILS_ENV=#{rails_env} db:database_dump --trace"
end
desc 'Downloads db/production_data.sql from the remote production environment to your local machine'
task :remote_db_download, :roles => :db, :only => { :primary => true } do
execute_on_servers(options) do |servers|
self.sessions[servers.first].sftp.connect do |tsftp|
tsftp.download!("#{deploy_to}/#{current_dir}/db/production_data.sql", "db/production_data.sql")
end
end
end
end
namespace :log do
desc 'Download production.log from remote production environment'
task :download do
logfile = "production.log"
execute_on_servers(options) do |servers|
self.sessions[servers.first].sftp.connect do |tsftp|
tsftp.download!("#{deploy_to}/#{current_dir}/log/#{logfile}", "log/#{logfile}")
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment