Andy Verbunt
Andy Verbunt

Reputation: 387

How to automatically restart Heroku dynos when application is failing?

Platforms such as Kubernetes have support for liveness and readiness probes: https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes

Basically, the (web) application needs to provide a specific http endpoint that is called every few seconds by the platform. If the application is unhealthy (typically indicated by a 5xx error) the platform restarts the application.

How does Heroku handle this?

Upvotes: 6

Views: 1533

Answers (1)

Shlomo
Shlomo

Reputation: 337

You can read about heroku's auto-restart policy here: Does heroku restart NodeJS server if application crashes

If you want to restart by force as soon as it crashes, you can do so via the dashboard - app management (https://dashboard.heroku.com/apps/[APP_NAME]) then on the top right: More> Restart all dynos: enter image description here

You can also do this using heroku cli: https://devcenter.heroku.com/articles/heroku-cli-commands#heroku-dyno-restart-dyno


In addition, I built a small Node.js app (can run on a separate free heroku account... 😃 Update: Heroku no longer has free plans) that monitors the app every 50 seconds, and as soon as status 200 does not return, restarts all dynos via heroku's api platform... Maybe it will inspire you or suit you, maybe with small changes. https://github.com/ShlomoCode/Heroku-dynos-restarter

Upvotes: 2

Related Questions