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 H开发者_运维技巧eroku 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
or use Heroku's own Maintenance mode exactly for this scenario - http://devcenter.heroku.com/articles/maintenance-mode
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
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.
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
精彩评论