Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
tree: 434309a401
Fetching contributors…

Cannot retrieve contributors at this time

96 lines (75 sloc) 3.559 kb
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:update", :copy_database_yml
after "deploy:update", :set_permissions
after "deploy:update", :update_sphinx
after "deploy:setup", :create_database
task :create_database, :role => [:web, :app] do
run "echo 'create database clojuredocs_production' | mysql -u#{db_user}"
end
task :copy_database_yml, :role => [:web, :app] do
run "cp #{release_path}/config/database.example.yml #{release_path}/config/database.yml"
end
task :set_permissions, :role => [:web, :app] do
run "mkdir -p #{release_path}/tmp/openids"
run "mkdir -p #{release_path}/tmp/openids/associations"
run "mkdir -p #{release_path}/tmp/openids/nonces"
run "mkdir -p #{release_path}/tmp/openids/temp"
run "chown -R nobody #{release_path}/tmp"
run "chown -R nobody #{release_path}/public"
run "touch #{release_path}/log/production.log"
run "chmod 0666 #{release_path}/log/production.log"
end
namespace :bundler do
task :create_symlink, :roles => :app do
shared_dir = File.join(shared_path, 'bundle')
release_dir = File.join(current_release, '.bundle')
run("mkdir -p #{shared_dir} && ln -s #{shared_dir} #{release_dir}")
end
task :bundle_new_release, :roles => :app do
bundler.create_symlink
run "cd #{release_path} && /opt/ruby-enterprise/bin/bundle install --without test"
end
end
after 'deploy:update_code', 'bundler:bundle_new_release'
task :update_sphinx, :role => [:web, :app] do
run("killall searchd; true")
run("cd #{deploy_to}/current && #{rake} thinking_sphinx:rebuild RAILS_ENV=production")
end
require 'yaml'
desc "Backup the remote production database"
task :backup, :roles => :db, :only => { :primary => true } do
filename = "#{application.downcase}.dump.#{Time.now.to_i}.sql.bz2"
file = "/tmp/#{filename}"
on_rollback { run "rm -f #{file}" }
db = YAML::load(ERB.new(IO.read(File.join(File.dirname(__FILE__), './config/database.yml'))).result)['production']
run "mysqldump -u #{db['username']} #{db['database']} | bzip2 -c > #{file}" do |ch, stream, data|
puts data
end
`mkdir -p ~/.#{application.downcase}_db_backups`
get file, File.expand_path("~/.#{application.downcase}_db_backups/#{filename}")
run "rm -f #{file}"
end
desc "Backup the database before running migrations"
before 'deploy:migrate', :backup
task :clean_dump, :roles => :db do
filename = "unprotected_dump.sql"
file = "/tmp/#{filename}"
on_rollback { run "rm -f #{file}" }
db = YAML::load(ERB.new(IO.read(File.join(File.dirname(__FILE__), './config/database.yml'))).result)['production']
run "echo 'create database clean_temp;' | mysql -u root"
run "mysqldump -u root clojuredocs_production > #{file}"
run "mysql -uroot clean_temp < #{file}"
run "rm -f #{file}"
run "echo 'use clean_temp; UPDATE users set login = MD5(RAND()), email = MD5(RAND()), openid_identifier = MD5(RAND()), password_salt = MD5(RAND()), crypted_password = MD5(RAND());' | mysql -u root"
filename = "clojuredocs_clean_dump.#{Time.now.to_i}.sql.bz2"
file = "/tmp/#{filename}"
run "mysqldump -u root clean_temp | bzip2 -c > #{file}" do |ch, stream, data|
puts data
end
run "echo 'drop database clean_temp;' | mysql -u root"
`mkdir -p ~/.#{application.downcase}_db_backups`
get file, File.expand_path("~/.#{application.downcase}_db_backups/#{filename}")
run "rm -f #{file}"
end
Jump to Line
Something went wrong with that request. Please try again.