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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With