Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 96 lines (75 sloc) 3.559 kb
99da426 @zk Initial commit after nuking history (pws and keys in history).
authored
1 load 'deploy' if respond_to?(:namespace) # cap2 differentiator
2 Dir['vendor/plugins/*/recipes/*.rb'].each { |plugin| load(plugin) }
3
4 load 'config/deploy' # remove this line to skip loading any of the default tasks
5
55da58f @zk Switched to including rcov tasks only if env != production
authored
6 after "deploy:update", :copy_database_yml
99da426 @zk Initial commit after nuking history (pws and keys in history).
authored
7 after "deploy:update", :set_permissions
8 after "deploy:update", :update_sphinx
9 after "deploy:setup", :create_database
10
11 task :create_database, :role => [:web, :app] do
55da58f @zk Switched to including rcov tasks only if env != production
authored
12 run "echo 'create database clojuredocs_production' | mysql -u#{db_user}"
13 end
14
15 task :copy_database_yml, :role => [:web, :app] do
16 run "cp #{release_path}/config/database.example.yml #{release_path}/config/database.yml"
99da426 @zk Initial commit after nuking history (pws and keys in history).
authored
17 end
18
19 task :set_permissions, :role => [:web, :app] do
58b1793 @zk Testing more flexible ajax root (i.e. root_url = "")
authored
20 run "mkdir -p #{release_path}/tmp/openids"
21 run "mkdir -p #{release_path}/tmp/openids/associations"
22 run "mkdir -p #{release_path}/tmp/openids/nonces"
23 run "mkdir -p #{release_path}/tmp/openids/temp"
55da58f @zk Switched to including rcov tasks only if env != production
authored
24 run "chown -R nobody #{release_path}/tmp"
25 run "chown -R nobody #{release_path}/public"
26 run "touch #{release_path}/log/production.log"
27 run "chmod 0666 #{release_path}/log/production.log"
99da426 @zk Initial commit after nuking history (pws and keys in history).
authored
28 end
29
55da58f @zk Switched to including rcov tasks only if env != production
authored
30 namespace :bundler do
31 task :create_symlink, :roles => :app do
32 shared_dir = File.join(shared_path, 'bundle')
33 release_dir = File.join(current_release, '.bundle')
34 run("mkdir -p #{shared_dir} && ln -s #{shared_dir} #{release_dir}")
35 end
36
37 task :bundle_new_release, :roles => :app do
38 bundler.create_symlink
39 run "cd #{release_path} && /opt/ruby-enterprise/bin/bundle install --without test"
40 end
99da426 @zk Initial commit after nuking history (pws and keys in history).
authored
41 end
55da58f @zk Switched to including rcov tasks only if env != production
authored
42
43 after 'deploy:update_code', 'bundler:bundle_new_release'
99da426 @zk Initial commit after nuking history (pws and keys in history).
authored
44
45 task :update_sphinx, :role => [:web, :app] do
46 run("killall searchd; true")
47 run("cd #{deploy_to}/current && #{rake} thinking_sphinx:rebuild RAILS_ENV=production")
c8080e2 @zk Updated cap, added db backup task
authored
48 end
49
50 require 'yaml'
51
52 desc "Backup the remote production database"
53 task :backup, :roles => :db, :only => { :primary => true } do
54 filename = "#{application.downcase}.dump.#{Time.now.to_i}.sql.bz2"
55 file = "/tmp/#{filename}"
56 on_rollback { run "rm -f #{file}" }
57 db = YAML::load(ERB.new(IO.read(File.join(File.dirname(__FILE__), './config/database.yml'))).result)['production']
58 run "mysqldump -u #{db['username']} #{db['database']} | bzip2 -c > #{file}" do |ch, stream, data|
59 puts data
60 end
61 `mkdir -p ~/.#{application.downcase}_db_backups`
62 get file, File.expand_path("~/.#{application.downcase}_db_backups/#{filename}")
63 run "rm -f #{file}"
64 end
65
66 desc "Backup the database before running migrations"
67 before 'deploy:migrate', :backup
58b1793 @zk Testing more flexible ajax root (i.e. root_url = "")
authored
68
c13b029 @zk Added db:clean_dump cap task, which anonymizes the database and dumps it
authored
69 task :clean_dump, :roles => :db do
70 filename = "unprotected_dump.sql"
71 file = "/tmp/#{filename}"
72 on_rollback { run "rm -f #{file}" }
73 db = YAML::load(ERB.new(IO.read(File.join(File.dirname(__FILE__), './config/database.yml'))).result)['production']
74 run "echo 'create database clean_temp;' | mysql -u root"
75 run "mysqldump -u root clojuredocs_production > #{file}"
76 run "mysql -uroot clean_temp < #{file}"
77
78 run "rm -f #{file}"
79
80 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"
81
82 filename = "clojuredocs_clean_dump.#{Time.now.to_i}.sql.bz2"
83 file = "/tmp/#{filename}"
84
85 run "mysqldump -u root clean_temp | bzip2 -c > #{file}" do |ch, stream, data|
86 puts data
87 end
88 run "echo 'drop database clean_temp;' | mysql -u root"
89
90 `mkdir -p ~/.#{application.downcase}_db_backups`
91 get file, File.expand_path("~/.#{application.downcase}_db_backups/#{filename}")
92 run "rm -f #{file}"
93
94 end
95
Something went wrong with that request. Please try again.