Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's a smart way to implement a Maintenance page in a Heroku app?

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

like image 389
AnApprentice Avatar asked Sep 02 '11 02:09

AnApprentice


1 Answers

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

like image 153
numbers1311407 Avatar answered Sep 17 '22 12:09

numbers1311407