forked from zk/clojuredocs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Capfile
95 lines (75 loc) · 3.48 KB
/
Capfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
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