Custom maintenance pages in Capistrano 2.0

Here is a version 2.0 amendment to Mike Clark’s great tutorial on creating custom maintenance pages with Capistrano. It’s required because, as Jamis explains here, render has been taken out of Capistrano 2.0.

namespace :deploy do
  namespace :web do
    task :disable, :roles => :web do
      # invoke with  
      # UNTIL="16:00 MST" REASON="a database upgrade" cap deploy:web:disable

      on_rollback { rm "#{shared_path}/system/maintenance.html" }

      require 'erb'
      deadline, reason = ENV['UNTIL'], ENV['REASON']
      maintenance = ERB.new(File.read("./app/views/layouts/maintenance.erb")).result(binding)

      put maintenance, "#{shared_path}/system/maintenance.html", :mode => 0644
    end
  end
end