Sha256: e62ffab69bbe3e6dd8d8c5d69bb6732b42f127dc0056d13c7610ca32ae2abf2d

Contents?: true

Size: 1.25 KB

Versions: 2

Compression:

Stored size: 1.25 KB

Contents

namespace :maintenance do
  desc "Turn on maintenance mode"
  task :enable do
    on fetch(:maintenance_roles) do
      require 'erb'

      reason = ENV['REASON']
      deadline = ENV['UNTIL']

      result = ERB.new(File.read(fetch(:maintenance_template_path))).result(binding)

      rendered_path = fetch(:maintenance_dirname)
      rendered_name = "#{fetch(:maintenance_basename)}.html"

      if test "[ ! -d #{rendered_path} ]"
        info 'Creating missing directories.'
        execute :mkdir, '-pv', rendered_path
      end

      rendered_fullpath = "#{rendered_path}/#{rendered_name}"
      upload! StringIO.new(result), rendered_fullpath
      execute "chmod 644 #{rendered_fullpath}"
    end
  end

  desc "Turn off maintenance mode"
  task :disable do
    on fetch(:maintenance_roles) do
      execute "rm -f #{fetch(:maintenance_dirname)}/#{fetch(:maintenance_basename)}.html"
    end
  end
end

namespace :load do
  task :defaults do
    set_if_empty :maintenance_roles, -> { roles(:web) }
    set_if_empty :maintenance_template_path,
      File.join(File.expand_path('../../templates', __FILE__), 'maintenance.html.erb')
    set_if_empty :maintenance_dirname, -> { "#{shared_path}/public/system" }
    set_if_empty :maintenance_basename, 'maintenance'
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
capistrano-maintenance-1.2.1 lib/capistrano/tasks/maintenance.rake
capistrano-maintenance-1.2.0 lib/capistrano/tasks/maintenance.rake