Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Revert "Remove the deploy:web:{disable, enable} tasks"

This reverts commit 4ece790.
  • Loading branch information...
commit ee2ec395c6827b89f8b7bcbdd5f186ff40f85a35 1 parent ef1c3a6
@leehambley leehambley authored
Showing with 69 additions and 0 deletions.
  1. +69 −0 lib/capistrano/recipes/deploy.rb
View
69 lib/capistrano/recipes/deploy.rb
@@ -555,4 +555,73 @@ def try_runner(*args)
system(source.local.log(from))
end
end
+
+ namespace :web do
+ desc <<-DESC
+ Present a maintenance page to visitors. Disables your application's web \
+ interface by writing a "#{maintenance_basename}.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 and UNTIL environment variables:
+
+ $ cap deploy:web:disable \\
+ REASON="hardware upgrade" \\
+ UNTIL="12pm Central Time"
+
+ You can use a different template for the maintenance page by setting the \
+ :maintenance_template_path variable in your deploy.rb file. The template file \
+ should either be a plaintext or an erb file.
+
+ Further customization will require that you write your own task.
+ DESC
+ task :disable, :roles => :web, :except => { :no_release => true } do
+ require 'erb'
+ on_rollback { run "rm -f #{shared_path}/system/#{maintenance_basename}.html" }
+
+ warn <<-EOHTACCESS
+
+ # Please add something like this to your site's Apache htaccess to redirect users to the maintenance page.
+ # More Info: http://www.shiftcommathree.com/articles/make-your-rails-maintenance-page-respond-with-a-503
+
+ ErrorDocument 503 /system/#{maintenance_basename}.html
+ RewriteEngine On
+ RewriteCond %{REQUEST_URI} !\.(css|gif|jpg|png)$
+ RewriteCond %{DOCUMENT_ROOT}/system/#{maintenance_basename}.html -f
+ RewriteCond %{SCRIPT_FILENAME} !#{maintenance_basename}.html
+ RewriteRule ^.*$ - [redirect=503,last]
+
+ # Or if you are using Nginx add this to your server config:
+
+ if (-f $document_root/system/maintenance.html) {
+ return 503;
+ }
+ error_page 503 @maintenance;
+ location @maintenance {
+ rewrite ^(.*)$ /system/maintenance.html last;
+ break;
+ }
+ EOHTACCESS
+
+ reason = ENV['REASON']
+ deadline = ENV['UNTIL']
+
+ template = File.read(maintenance_template_path)
+ result = ERB.new(template).result(binding)
+
+ put result, "#{shared_path}/system/#{maintenance_basename}.html", :mode => 0644
+ end
+
+ desc <<-DESC
+ Makes the application web-accessible again. Removes the \
+ "#{maintenance_basename}.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
+ run "rm -f #{shared_path}/system/#{maintenance_basename}.html"
+ end
+ end
end

3 comments on commit ee2ec39

@greendog

i have an error:
/bundler/gems/capistrano-ee2ec395c682/lib/capistrano/configuration/namespaces.rb:193:in method_missing': undefined local variable or method 'maintenance_basename' for #<Capistrano::Configuration::Namespaces::Namespace:0x9642fe0> (NameError)
from /bundler/gems/capistrano-ee2ec395c682/lib/capistrano/recipes/deploy.rb:562:in
block (2 levels) in load'

@leehambley
Owner

@greendog Don't use the HEAD branch. It's a WIP, as you can see from this thread there's a discussion in progress about how to resolve this problem, and It's not resolved yet. Take the latest release with @tvdeyen's gem, or wait for the next release.

You should never use Capistrano master/HEAD, it's a minefield.

@greendog

I see. Thanks.

Please sign in to comment.
Something went wrong with that request. Please try again.