Skip to content


Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
This branch is 4 commits behind capistrano:master.

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time



Add this line to your application's Gemfile:

gem 'capistrano', '~> 3.0'
gem 'capistrano-maintenance', '~> 1.0', require: false

And then execute:

$ bundle

Or install it yourself:

$ gem install capistrano-maintenance


Before using the maintenance tasks, you need to configure your webserver. How you do this depends on how your server is configured, but the following examples should help you on your way.

Application servers such as Passenger and unicorn requires you to set your public web directory to current/public. Both examples below are compatible with this setup.

Here is an example config for nginx. Note that this is just a part of the complete config, and will probably require modifications.

error_page 503 @503;

# Return a 503 error if the maintenance page exists.
if (-f /var/www/ {
  return 503;

location @503 {
  # Serve static assets if found.
  if (-f $request_filename) {

  # Set root to the shared directory.
  root /var/www/;
  rewrite ^(.*)$ /system/maintenance.html break;

And here is an example config for Apache. This will also need to be modified.

# Create an alias to the maintenance page used as error document.
Alias "/error" "/var/www/"
ErrorDocument 503 /error/maintenance.html

# Return 503 error if the maintenance page exists.
RewriteCond /var/www/ -f
RewriteRule !^/error/maintenance.html - [L,R=503]

# Redirect all non-static requests to unicorn (or similar).
# Will not redirect any requests if the maintenance page exists.
RewriteCond /var/www/ !-f
RewriteRule ^/(.*)$ balancer://unicornserver%{REQUEST_URI} [P,QSA,L]

You can now require the gem in your 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 with an absolute path.

set :maintenance_template_path, File.expand_path("../../app/path/to/maintenance.erb.html", __FILE__)

The template file should either be a plaintext or an erb file. For example:

<!DOCTYPE html>
    <style type="text/css">
    body {
        width: 400px;
        margin: 100px auto;
        font: 300 120% "OpenSans", "Helvetica Neue", "Helvetica", Arial, Verdana, sans-serif;

    h1 {
        font-weight: 300;

    <p>The system is down for <%= reason ? reason : "maintenance" %><br>
           as of <%="%F %H:%M %Z") %>.</p>

    <p>It'll be back <%= deadline ? deadline : "shortly" %>.</p>

You can customize which folder the maintenance page template is rendered to by setting the :maintenance_dirname variable. By default it renders to "#{shared_path}/public/system".

set :maintenance_dirname, -> { "#{current_path}/dist" }

By default, the maintenance page will be uploaded to all servers with the web role, but if your application has different needs, you can customize this using the maintenance_roles variable:

set :maintenance_roles, -> { roles([:web, :other_role]) }

Further customization will require that you write your own task.

Disable task

cap maintenance:disable

Makes the application web-accessible again. Removes the "#{maintenance_basename}.html" page generated by maintenance:disable, which (if your web servers are configured correctly) will make your application web-accessible again.


  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request


The original capistrano-maintenance gem was created by Thomas von Deyen and the implementation for Capistrano 3 in this repo was written by Kir Shatrov.

As a Capistrano team, we thank Thomas for collaboration and providing the push access to the capistrano-maintenance gem.


Maintenance Page Support For Capistrano







No packages published


  • Ruby 82.6%
  • HTML 17.4%