Health checks

Health checks

A deploy only counts once the service is healthy. muster decides that by running the service's health.sh hook.

How it works

After deploy.sh succeeds, muster runs .muster/hooks/<service>/health.sh (or a health justfile recipe). Exit 0 means healthy; anything else means unhealthy. The same hook runs for muster status, muster dev and the dashboard. For remote services it runs on the remote host.

The type in muster.json (http, tcp or command) doesn't replace the hook: setup uses it to generate health.sh, and status, explain and doctor use it to probe a failing service and name the cause (wrong port, refused, timeout, 4xx, 5xx).

Configure a check

Pick the check when you run setup, or pass it as a flag:

Terminal
muster setup --scan --health api=http:/health:8080
muster setup --scan --health redis=tcp:6379
muster setup --scan --health worker=command:./check.sh
muster setup --scan --health api=none
muster.json
"api": {
  "health": {
    "enabled": true,
    "type": "http",
    "endpoint": "/health",
    "port": 8080,
    "timeout": 30
  }
}

Write your own check

health.sh gets the same environment as every other hook, including credentials. Check what actually matters for the service:

.muster/hooks/api/health.sh
#!/usr/bin/env bash
set -euo pipefail

curl -sf http://localhost:8080/health > /dev/null
pg_isready -h db -U app

When a check fails

In a terminal, muster asks what to do:

OptionWhat it does
Continue anywayGo on to the next service.
Rollback <name>Run the service's rollback hook.
AbortStop the deploy.

Without a terminal the service is recorded as unhealthy and the deploy exits 1. muster explain shows the likely cause.

Health keys

KeyDescription
enabledfalse turns the check off.
typehttp, tcp or command.
endpointPath for http checks.
portPort for http and tcp checks.
commandCommand for command checks.
timeoutSeconds. The setup wizard sets 30 (production), 15 (staging) or 5 (development); otherwise default_health_timeout (10).