Posted about 4 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):


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.

Once an application no longer requires constant development, it needs periodic maintenance for stable and secure operation. makandra offers monthly maintenance contracts that let you focus on your business while we make sure the lights stay on.

Owner of this card:

Pascal Roth
Last edit:
about 4 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