/
Capfile
115 lines (100 loc) · 3.31 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
load 'deploy' if respond_to?(:namespace) # cap2 differentiator
Dir['vendor/plugins/*/recipes/*.rb'].each { |plugin| load(plugin) }
require 'mongrel_cluster/recipes'
load 'config/deploy'
autoload :ERB, 'erb'
namespace :db do
desc "Generate config/database.yml for production environment after deploy:setup"
task :init_config, :only => "app" do
$stderr.print('User name: '); username = $stdin.gets.chomp
password = Capistrano::CLI.password_prompt("database password:")
template = ERB.new(File.read("./config/database.yml.erb"))
config = template.result(binding)
run "mkdir -p #{shared_path}/config"
put config, "#{shared_path}/config/database.yml"
end
after 'deploy:setup', 'db:init_config'
desc "Applies config/database.yml for production environment to the deployed code"
task :apply_config, :only => "app" do
run <<-"EOS"
cd #{latest_release}/config && ln -sf #{shared_path}/config/database.yml .
EOS
end
after 'deploy:update_code', 'db:apply_config'
namespace :backup do
desc "Backups the production database of remote servers"
task :default, :roles => :db, :only => { :primary => true } do
run <<-"CMD"
cd #{latest_release} &&
/usr/bin/env PATH='#{db_bin_path}' #{latest_release}/script/database/backup
CMD
end
before 'deploy:migrate', 'db:backup:default'
desc "Prepares backup/ directory"
task :prepare do
run "ln -s #{shared_path}/backup #{latest_release}/backup"
end
after 'deploy:update_code', 'db:backup:prepare'
desc "List the backups of the remote production database"
task :list do
run "ls #{shared_path}/backup/"
end
end
end
namespace :mail do
desc 'starts mail receiving daemon'
task :start do
run <<-"CMD"
cd #{latest_release} &&
/usr/bin/env RAILS_ENV=production #{latest_release}/script/daemons start
CMD
end
desc 'restarts mail receiving daemon'
task :restart do
run <<-"CMD"
cd #{latest_release} &&
/usr/bin/env RAILS_ENV=production #{latest_release}/script/daemons restart
CMD
end
after 'deploy:update', 'mail:restart'
desc 'stops mail receiving daemon'
task :stop do
run <<-"CMD"
cd #{latest_release} &&
/usr/bin/env RAILS_ENV=production #{latest_release}/script/daemons stop
CMD
end
task :check do
run <<-"CMD"
cd #{latest_release} &&
/usr/bin/env RAILS_ENV=production #{latest_release}/script/mail_checker
CMD
end
task :list do
run <<-"CMD"
ls #{latest_release}/tmp/mail
CMD
end
end
desc '[internal]'
task :setup_dirs do
run <<-"CMD"
mkdir #{shared_path}/cache 2>/dev/null || true; \
mkdir #{shared_path}/sessions 2>/dev/null || true; \
mkdir #{shared_path}/mail 2>/dev/null || true; \
ln -s #{shared_path}/cache #{latest_release}/tmp/; \
ln -s #{shared_path}/sessions #{latest_release}/tmp/; \
ln -s #{shared_path}/mail #{latest_release}/tmp/;
rm #{latest_release}/files/delete.me &&
rmdir #{latest_release}/files &&
ln -s #{shared_path}/files #{latest_release}/files
CMD
end
after 'deploy:update_code', :setup_dirs
desc "fixes ths shebang's of script/**/*"
task :fix_shebang do
run <<-"CMD".gsub(/^ +/, '')
find #{latest_release}/script -type f -exec #{latest_release}/script/fix_path '{}' ';'
CMD
end
after 'deploy:update_code', :fix_shebang