Posted over 6 years ago. Visible to the public. Repeats. Linked content.

Showing a custom maintenance page while deploying

Add a custom maintenance page for each vhost. We have automated this with capistrano 3.x, but you can do it manually by following the instructions at the bottom:


Add this line to your application's Gemfile:

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

Add this line to you application's Capfile:

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:

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:

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

The erb file can look like this file:

<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

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.

Manual steps

If you are still on capistrano 1, you can enable and disable the maintenance page manually.

First, prepare a maintenance.html, for example by using the template above.

Then, to enable maintenance mode, copy this file using scp to /public/system/maintenance.html on the server. Since the directory lives in gluster, you do not have to upload it to each server individually.

To disable maintenance mode, delete the file.

Does your version of Ruby on Rails still receive security updates?
Rails LTS provides security patches for unsupported versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2).

Owner of this card:

Pascal Roth
Last edit:
almost 2 years ago
by Tobias Kraze
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 short-lived cookies to improve usability.
Accept or learn more