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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
|
# File 'lib/yad/core.rb', line 62
def self.define_tasks
return if @tasks_already_defined
@tasks_already_defined = true
namespace :yad do
desc "Prepares one or more servers for deployment"
remote_task :setup do
Rake::Task['yad:core:setup_deployment'].invoke
Rake::Task.invoke_if_defined('yad:framework:setup', :framework)
end
desc "Copies files to the shared/config directory using FILES=a,b,c (e.g. rake vlad:upload_config_files FILES=config/database.yml,config/maintenance.html)"
remote_task :upload_config_files do
files = Yad::Core.build_files_array(ENV["FILES"])
if files.empty?
puts("Please specify at least one file to upload (via the FILES environment variable)")
else
files.each do |file|
rsync(file, "#{target_host}:#{File.join(shared_config_path, File.basename(file))}")
end
puts("uploaded #{files.inspect} to #{target_host}")
end
end
desc "Creates the database for the application"
remote_task :create_db, :roles => :app do
Rake::Task.invoke_if_defined('yad:db:create', :db, "Please specify the database delegate via the :db variable")
end
desc "Updates the application servers to the latest version"
remote_task :update, :roles => :app do
Rake::Task.invoke_if_defined('yad:scm:update', :scm)
Rake::Task.invoke_if_defined('yad:framework:update', :framework)
Rake::Task['yad:core:update_symlink'].invoke
end
desc "Runs migrations for the database for the application"
remote_task :migrate_db, :roles => :app do
Rake::Task.invoke_if_defined('yad:db:migrate', :db, "Please specify the database delegate via the :db variable")
end
desc "Starts the application server"
remote_task :start_app, :roles => :app do
Rake::Task.invoke_if_defined('yad:app:start', :app, "Please specify the app delegate via the :app variable")
end
desc "Starts the web server"
remote_task :start_web, :roles => :web do
Rake::Task.invoke_if_defined('yad:web:start', :web, "Please specify the web delegate via the :web variable")
end
"Stops the web server"
remote_task :stop_web, :roles => :web do
Rake::Task.invoke_if_defined('yad:web:stop', :web, "Please specify the web delegate via the :web variable")
end
desc "Stops the application server"
remote_task :stop_app, :roles => :app do
Rake::Task.invoke_if_defined('yad:app:stop', :app, "Please specify the app delegate via the :app variable")
end
desc "Turns on the maintenance page for the application"
remote_task :turn_on_maintenance, :roles => :web do
Rake::Task.invoke_if_defined('yad:maintenance:turn_on', :maintenance, "Please specify the maintenance delegate via the :maintenance variable")
end
desc "Turns off the maintenance page for the application"
remote_task :turn_off_maintenance, :roles => :web do
Rake::Task.invoke_if_defined('yad:maintenance:turn_off', :maintenance, "Please specify the maintenance delegate via the :maintenance variable")
end
desc "Rolls back to the previous release, but DOES NOT restart the application"
remote_task :rollback do
cmd = Yad::Core.build_rollback_command(current_path, previous_release, latest_release)
if cmd.length == 0
puts("could not rollback the code because there is no previous release")
else
run(cmd)
puts("rolled back to #{File.basename(previous_release)} on #{target_host}")
end
end
desc "Cleans up old releases"
remote_task :cleanup do
cmd = Yad::Core.build_cleanup_command(keep_releases, releases_path, releases)
run(cmd)
puts("old releases cleaned up on #{target_host}")
end
remote_task :invoke do
end
namespace :core do
remote_task :setup_deployment, :roles => :app do
options = Rake::RemoteTask.get_options_hash(:umask, :shared_subdirectories)
cmd = Yad::Core.build_setup_command(deploy_to, options)
run(cmd)
puts("Yad set up on #{target_host}")
end
remote_task :update_symlink, :roles => :app do
begin
symlinked = false
cmd = Yad::Core.build_update_symlink_command(current_path, release_path)
run(cmd)
puts("'current' symlink updated on #{target_host}")
symlinked = true
scm_value = Rake::RemoteTask.fetch(:scm, false)
if scm_value
scm_class = eval("Yad::Scm::#{scm_value.to_s.classify}")
options = Rake::RemoteTask.get_options_hash(:revision)
inline_command = scm_class.build_inline_revision_identifier_command(scm_path, options)
else
inline_command = 'none'
end
cmd = Yad::Core.build_revision_log_command(Time.now.utc.strftime("%Y%m%d%H%M.%S"), inline_command, release_path, deploy_to)
run(cmd)
rescue => e
if releases.length > 1 && symlinked then
cmd = Yad::Core.build_update_symlink_command(current_path, previous_release)
run(cmd)
end
cmd = Yad::Core.build_remove_directory_command(release_path)
run(cmd)
raise e
end
end
end
end
end
|