Maintenance Mode
Last updated May 07, 2024
Table of Contents
If you need to temporarily disable access to your Heroku app (for example, to perform a large migration), you can enable Heroku’s built-in maintenance mode. While in maintenance mode, your app serves a static maintenance page to all visitors.
While maintenance mode is active, the error code H80 is returned in your logs.
Scheduler jobs can still run while your app is in maintenance mode. Be mindful if you have any jobs set to run.
Usage
To enable maintenance mode:
$ heroku maintenance:on
Enabling maintenance mode for myapp... done
To disable maintenance mode:
$ heroku maintenance:off
Disabling maintenance mode for myapp... done
To check the current maintenance status of an app:
$ heroku maintenance
off
Maintenance mode and dynos
Enabling or disabling maintenance mode does not alter your app’s dyno formation. Dynos continue to accrue billing hours while in maintenance mode. Web dynos continue to run, but Heroku’s routers block all incoming HTTP requests to them. Dynos of other types (such as worker dynos) also continue to run, and you can run one-off dynos as usual.
Scaling dynos in maintenance mode
It can be useful to scale your app’s dynos to zero during maintenance operations. For example, doing so can prevent database transactions from taking place.
First, enable maintenance mode:
$ heroku maintenance:on
Enabling maintenance mode for myapp... done
Check the current dyno formation, so you know what values to restore after maintenance, and then scale your dynos to zero:
$ heroku ps
web=3:Private-M worker=2:Private-M
$ heroku ps:scale worker=0
Scaling worker processes... done, now running 0
You can do the same for any of an app’s process types, such as web
.
Avoid scaling web=0
in Private Spaces. Doing so causes app response errors instead of serving the maintenance page, because the routing proxy in spaces resides on the web dynos’ compute instances.
You can run one-off dynos to perform maintenance activities or check the app’s health after database upgrades.
$ heroku run bash
After maintenance activities complete, scale the dynos up:
$ heroku ps:scale worker=2
Scaling worker processes... done, now running 2
Disable maintenance mode:
$ heroku maintenance:off
Disabling maintenance mode for myapp... done
Customizing your maintenance page
You can specify a custom maintenance page for your app by setting the following config var:
heroku config:set MAINTENANCE_PAGE_URL=//s3.amazonaws.com/<your_bucket>/your_maintenance_page.html
Please see this article for more information.