Posted about 3 years ago. Visible to the public. Repeats. Linked content.

Showing a custom maintenance page while deploying

Add a custom maintenance page for each vhost (require capistrano 3.x):

Installation

Add this line to your application's Gemfile:

Copy
gem 'capistrano', '~> 3.0' gem 'capistrano-maintenance', '~> 1.0'

Add this line to you application's Capfile:

Copy
require 'capistrano/maintenance'

Enable task

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:

Copy
cap maintenance:enable 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:

Copy
set :maintenance_template_path, 'public/maintenance.html.erb'

The erb file can look like this file:

Copy
<html> <head> <meta content='text/html; charset=UTF-8' http-equiv='Content-Type'> <title>Anwendung wird gewartet</title> <style> body { text-align: center; margin: 100px 20px; } h1 { font-size: 50px; } body { font: 20px Helvetica, sans-serif; color: #333; } article { display: block; text-align: left; max-width: 650px; margin: 0 auto; } a { color: #dc8100; text-decoration: none; } a:hover { color: #333; text-decoration: none; } </style> </head> <body> <article> <h1>Wartungsarbeiten</h1> <p> Diese Anwendung wird <%= reason %> gerade gewartet und ist <%= deadline || 'in Kürze' %> wieder verfügbar. </p> <p> Wir bitten um Ihr Verständnis. </p> </article> </body>

Further customization will require that you write your own task.

The path for the maintenance.html is /var/www/<project>/shared/public/system.

Disable task

Copy
cap maintenance:disable

Makes the application web-accessible again. Removes the #{maintenance_basename}.html page generated by maintenance:disable, which will make your application web-accessible again.

makandra has been working exclusively with Ruby on Rails since 2007. Our laser focus on a single technology has made us a leader in this space.

Owner of this card:

Avatar
Pascal Roth
Last edit:
about 3 years ago
by Henning Koch
About this deck:
We are makandra and do test-driven, agile Ruby on Rails software development.
License for source code
Posted by Pascal Roth to makandra dev
This website uses cookies to improve usability and analyze traffic.
Accept or learn more