namespace :deploy do namespace :web do set(:maint_files) {["#{shared_path}/system/maintenance.html"]} desc <<-DESC Present a maintenance page to visitors. Disables your application's web \ interface by writing a "maintenance.html" file to each web server. The \ servers must be configured to detect the presence of this file, and if \ it is present, always display it instead of performing the request. By default, the maintenance page will just say the site is down for \ "maintenance", and will be back "shortly", but you can customize the \ page by specifying the REASON environment variable: $ cap deploy:web:disable \\ REASON="hardware upgrade" Further customization will require that you write your own task. DESC task :disable, :roles => :web, :except => { :no_release => true } do require 'erb' on_rollback { maint_files.each do |file| run "if [ -e #{file} ]; then rm #{file}; fi" end } reason = ENV['REASON'] template = File.read("public/maintenance.rhtml") result = ERB.new(template).result(binding) maint_files.each do |file| dir=File.dirname(file) tmpfile=%x{mktemp -u /tmp/capXXXXXXXX} # this seems like the quickest way to just get a name. tmpfile.chomp! put result, tmpfile, :mode => 0644 run "if [ -d #{dir} -a \! -e #{file} ]; then mv #{tmpfile} #{file}; fi" run "chcon -t httpd_sys_content_t #{file}; true" # we ignore this since some hosts have home on nfs end end desc <<-DESC Makes the application web-accessible again. Removes the \ "maintenance.html" page generated by deploy:web:disable, which (if your \ web servers are configured correctly) will make your application \ web-accessible again. DESC task :enable, :roles => :web, :except => { :no_release => true } do maint_files.each do |file| run "if [ -e #{file} ]; then rm #{file}; fi" end end end end