Enable Rails 7.1.2 Health Check Endpoint

Enable Rails 7.1.2 Health Check Endpoint
Photo by Hush Naidoo Jade Photography / Unsplash

I upgrade my rails project and tend to run on the latest stable version. Doing those upgrades tends to wipe out my configs so I will usally do them manually. In this case I missed a really cool feature - the health check endpoint at \up.

Setting this up is fairly easy! Add these lines to the top of your routes file:

Rails.application.routes.draw do
  # Reveal health status on /up that returns 200 if the app boots with no exceptions, otherwise 500.
  # Can be used by load balances and uptime moniors to verify the app is live.
  get 'up' => 'rails/health#show', as: :rails_health_check
Added up route to routes.rb

Now if you visit your running app's \up path you should be presented with a green screen for a running app, and a red one for a failed.

Green status page

If you host on fly.io you can take advantage of this new endpoint by modifying your fly.toml to include the health checks as shown here:

  internal_port = 3000
  force_https = true
  auto_stop_machines = true
  auto_start_machines = true
  min_machines_running = 1
  processes = ["app"]

    port = 3000
    type = "http"
    interval = "10s"
    timeout = "2s"
    grace_period = "5s"
    method = "GET"
    path = "/up"
    protocol = "http"
    tls_skip_verify = false
      X-Forwarded-Proto = "https"
fly.toml added configuration to use health checks