diff --git a/bin/capify b/bin/capify index f5a2abb8..ccaf70f9 100755 --- a/bin/capify +++ b/bin/capify @@ -50,16 +50,17 @@ files = { # and restart your mongrel application, or if you rely on the database # migration code, please uncomment the lines you require below - # require 'recipes/rails/mongrel' - # require 'recipes/rails/migrations' - # require 'recipes/rails/passenger_mod_rails' + # require 'ext/recipes/rails/mongrel' + # require 'ext/recipes/rails/migrations' + # require 'ext/recipes/rails/passenger_mod_rails' # There are also new utility libaries shipped with the core these # include the following, please see individual files for more # documentation, or run `cap -T` with the following lines commented out # to see what they make available. - # require 'recipes/apache' + # require 'ext/recipes/apache' + # require 'ext/recipes/web-disable-enable' # If you aren't deploying to /u/apps/\#{application} on the target # servers (which is the default), you can specify the actual location diff --git a/lib/capistrano/recipes/ext/web-disable-enable.rb b/lib/capistrano/recipes/ext/web-disable-enable.rb new file mode 100644 index 00000000..c6f84fa4 --- /dev/null +++ b/lib/capistrano/recipes/ext/web-disable-enable.rb @@ -0,0 +1,40 @@ +namespace :web do + 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 and UNTIL environment variables: + + $ cap deploy:web:disable \\ + REASON="hardware upgrade" \\ + UNTIL="12pm Central Time" + + 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 #{shared_path}/system/maintenance.html" } + + reason = ENV['REASON'] + deadline = ENV['UNTIL'] + + template = File.read(File.join(File.dirname(__FILE__), "templates", "maintenance.rhtml")) + result = ERB.new(template).result(binding) + + put result, "#{shared_path}/system/maintenance.html", :mode => 0644 + 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 + run "rm #{shared_path}/system/maintenance.html" + end +end \ No newline at end of file