11

is there a clean, elegant way to implement a Maintenance page in a Heroku app? So that if something breaks you can very easily turn a switch and the maintenance page goes up for all requests? Preferably a way that doesn't require a push?

Ideas? Thanks

numbers1311407
  • 33,686
  • 9
  • 90
  • 92
AnApprentice
  • 108,152
  • 195
  • 629
  • 1,012
  • http://stackoverflow.com/questions/2244263/capistrano-to-deploy-rails-application-how-to-handle-long-migrations has similar discussion and solution for apache. – leenasn Sep 03 '11 at 09:34

5 Answers5

14

NOTE This answer addresses nginx or Rack setups, as it was written before edits to the original question made it clear that was looking for an answer specific to Heroku. The accepted answer is best for Heroku apps.


When you say "in your app" do you really mean in your app?

Because typically the solution is to drop a maintenance file in your web root. If the file is found, it is served with a 503 Service Not Available immediately. The request never even makes it to your app, which is presumably "down for maintenance".

In nginx, something like this:

    location / {
       if (-f $document_root/maintenance.html) {
            return 503;
       }

       # continued server directives
     }

    error_page 503 @maintenance;
    location @maintenance {
            rewrite ^(.*)$ /maintenance.html break;
    }

It wouldn't really require a push per se, but perhaps a simple rake task or something to add/remove that maintenance file from your app. You could probably also replace any given filename in the -f check, and simply touch an empty arbitrary maintenance.whatever file in your web root, which would then direct nginx to serve the mainenance.html.

If you don't want to (or can't) mess around with the server config, this very simple Rack middleware does essentially the same thing: https://github.com/ddollar/rack-maintenance

numbers1311407
  • 33,686
  • 9
  • 90
  • 92
  • Using one of the Rack middleware solutions (such as one mentioned in answer), has anyone successfully got it to work when the DB is down? – yuяi Apr 04 '17 at 18:04
7

or use Heroku's own Maintenance mode exactly for this scenario - http://devcenter.heroku.com/articles/maintenance-mode

John Beynon
  • 37,398
  • 8
  • 88
  • 97
1

To add on Emanuel's answer:

Trackman helps with your maintenance pages from dev to prod.

You can

  • Scaffold them using your current site layout (~0 html editing)
  • Link your current assets within your static page
  • Look at your page layout within your dev environment

It will deploy everything to S3 when you push to Heroku and you don't even have to setup an account on S3.

You also have to run

rake trackman:setup

So Heroku points to your S3 pages while on maintenance mode.

http://www.trackman-addon.com

jfabre
  • 514
  • 5
  • 13
0

The answeres above are all right for a basic scenario.

For the smart part of your question here is an addon that will get you there:

https://addons.heroku.com/trackman

Emanuel
  • 610
  • 6
  • 15
0

This would probably be easily accomplished by appending a before_filter at the beginning of the filter chain that checks for a maintenance mode condition and redirects to the maintenance page when appropriate.

Don Roby
  • 40,677
  • 6
  • 91
  • 113