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
|
# File 'lib/capistrano-custom-maintenance.rb', line 8
def self.extended(configuration)
configuration.load {
namespace(:maintenance) {
_cset(:maintenance_template_path, File.expand_path("templates", File.dirname(__FILE__)))
_cset(:maintenance_content_type, "text/html")
_cset(:maintenance_suffix) { MIME::Types[maintenance_content_type].map { |type| type.extensions }.flatten.first
}
_cset(:maintenance_basename, "maintenance")
_cset(:maintenance_filename) { "#{maintenance_basename}.#{maintenance_suffix}" } _cset(:maintenance_system_path) { File.join(shared_path, maintenance_document_path) } _cset(:maintenance_document_path) { File.join("/system", maintenance_filename) } _cset(:maintenance_timestamp) { Time.now }
_cset(:maintenance_reason) { ENV.fetch("REASON", "maintenance") }
_cset(:maintenance_deadline) { ENV.fetch("UNTIL", "shortly") }
def template(name, options={})
reason = fetch(:maintenance_reason)
deadline = fetch(:maintenance_deadline)
options = {
:path => maintenance_template_path,
:binding => binding,
}.merge(options)
options[:external_encoding] = fetch(:maintenance_input_encoding) if exists?(:maintenance_input_encoding)
result = top.template(name, options)
exists?(:maintenance_output_encoding) ? result.encode(fetch(:maintenance_output_encoding)) : result
end
}
namespace(:deploy) {
namespace(:web) {
task(:disable, :roles => :web, :except => { :no_release => true }) {
on_rollback do
find_and_execute_task("deploy:web:enable")
end
top.put(maintenance.template(maintenance_filename), maintenance_system_path, :mode => "644")
}
task(:enable, :roles => :web, :except => { :no_release => true }) {
run("rm -f #{maintenance_system_path.dump}")
}
}
}
}
end
|