Health and restarts
This page explains when cairn restarts your app, how health checks work, and what each state in cairn ps and cairn status means. Deploying, stopping and pausing are in Deploying and updates.
Restarts
By default, cairn restarts your app when it fails. You can change this in cairn.toml:
[restart]
policy = "on-failure" # "never", "on-failure" (the default) or "always"
max_restarts = 10 # optional: give up after this many failures in a row (up to 10000)| Policy | Restarts when your program… |
|---|---|
never | never |
on-failure | exits with a non-zero code, is killed by a signal (including running out of memory), or the VM panics, resets, hangs or fails a health check set to restart. Not after a clean exit with code 0. |
always | ends for any reason, including a clean exit |
Whatever the policy:
- If Firecracker itself dies, the VM is always recovered.
- A program that can't start (its command doesn't exist, or its configuration is refused) isn't restarted, because trying again won't help.
- A stop you asked for is never followed by a restart.
Waiting between restarts
Each restart in a row waits twice as long as the one before, up to a minute:
| Restart in a row | 1 | 2 | 3 | 4 | 5 | 6 | 7 and after |
|---|---|---|---|---|---|---|---|
| Wait | 1 s | 2 s | 4 s | 8 s | 16 s | 32 s | 60 s |
The count goes back to zero once the VM has run for 2 minutes without failing. Time spent paused counts as running.
If max_restarts is reached, cairn gives up and the app's state becomes failed. cairn ps shows the count in the RESTARTS column, and cairn status lists the last ten failures, so a crash loop is easy to spot.
A restart reuses the VM and settings from the last deploy. It doesn't read your cairn.toml, your .env file or your shell again. Only a deploy does.
Hung VMs
The VM sends cairn a heartbeat. If no heartbeat arrives for 45 seconds, cairn asks Firecracker whether the VM is running. If the VM is still running but silent for another 3 seconds, it's treated as hung: cairn kills it, and the restart policy decides what happens next.
Health checks
A health check is a test that runs inside the VM every few seconds. It tells you, and optionally cairn, whether your app is working, not just whether it's running.
[checks.web]
http = "/healthz" # GET this path; any 2xx response passes
interval = "10s" # how often
timeout = "2s" # how long one check may take
failures = 3 # failures in a row before the app is unhealthy
grace = "30s" # time allowed for start-up
on_failure = "report" # "report" (the default) or "restart"Each check is one of three kinds:
| Kind | Example | Passes when |
|---|---|---|
http | http = "/healthz" | A GET request gets a 2xx response, or one of the codes listed in status = [...]. |
tcp | tcp = 5432 | The port accepts a connection. |
exec | exec = ["pg_isready"] | The command exits with code 0. |
If the app has no TCP service, or more than one, add port = 8080 to an http check to say which port to use. You can define several checks with different names, such as [checks.web] and [checks.db].
What happens when a check fails:
- With
on_failure = "report", the health shown incairn pschanges tounhealthy. Nothing else happens. - With
on_failure = "restart", afterfailuresfailures in a row cairn kills the VM, and the restart policy decides what happens next. This needsfailuresof at least 2 and a restart policy other thannever.
Start-up grace. Failures don't count while the app is younger than grace and the check hasn't passed yet. The first pass ends the grace period early.
Health checks during a deploy. A deploy waits for every check to pass before it accepts the new VM. See Deploying: when is a VM ready?
| Setting | Default | Allowed |
|---|---|---|
interval | 10 s | 1 s to 1 h |
timeout | 2 s | 100 ms up to interval |
failures | 3 | 1 to 10 |
grace | 30 s | 0 to 15 min |
Inside an exec check, the variable CAIRN_CHECK_ADDR holds the address the http and tcp checks use. Every key is listed in cairn.toml.
The HEALTH column
| Health | Meaning |
|---|---|
healthy | Every check passes. |
starting | Still within the start-up grace period. |
unhealthy | A check has failed failures times in a row. |
unknown | The latest result is too old to trust. cairn never shows an old healthy. |
- | No checks are defined, or the app isn't running. |
States
cairn ps and cairn status <app> show one state for each VM:
| State | Meaning |
|---|---|
running | Your program is running. |
starting | Preparing, booting, or waiting for its network. |
stopping | A stop is in progress. |
restarting | Your program ended, and cairn is waiting to start it again. |
paused | Paused with cairn pause. |
frozen | Its process was stopped by a signal, or its systemd unit was frozen. cairn resume releases it. |
stopped | Stopped on purpose, or never started. |
exited | Your program ended, and the restart policy didn't restart it. |
crashed | The VM or its supervisor died without being asked to stop. Under systemd, a killed supervisor shows crashed for about a second until systemd starts a new one. |
failed | It couldn't start, or cairn gave up restarting it. |
unsupervised | The VM is running but its supervisor isn't. cairn stop stops it. |
held | (ps only.) A deploy failed after it may have changed the app's volumes, so nothing will start the app until you decide. See Volumes. |
unknown | cairn can't tell. It never claims something is running or gone unless it has checked. |
none | The app exists but has no VM yet. |
running (no network) means the VM is running but its network agent restarted underneath it (this can happen with the direct launcher). cairn doesn't restart the VM behind your back. Run cairn stop <app> && cairn start <app>.
How cairn works out the state
cairn reads the records first, then checks whether the processes they name are still alive. It asks neither Firecracker nor systemd, so ps and status answer instantly, even for a VM that's stuck. A process counts as alive only if its process id, its start time and the current boot all match the record.
The first row that matches wins:
| # | Condition | State |
|---|---|---|
| 1 | A record can't be read, it can't be confirmed whether the supervisor or VM is alive, or the VM's cgroup freezer can't be read | unknown, with the reason |
| 2 | No run file | stopped ("never started"), or none for an app with no VM |
| 3 | The VM process is stopped by a signal (T/t in /proc), or its cgroup is frozen | frozen |
| 4 | The VM process runs, and the run file records a pause | paused |
| 5 | The supervisor runs, and is preparing, booting or waiting for the network | starting |
| 6 | The supervisor runs, the run file says running, and the VM process runs | running |
| 7 | The supervisor runs, and the VM process has ended or a stop is under way | stopping |
| 8 | The supervisor runs, and is waiting to restart your program | restarting |
| 9 | The supervisor runs, and the run has ended (it is finishing) | the ending's state, as row 11 |
| 10 | The supervisor has ended but the VM process runs | unsupervised |
| 11 | Neither runs, and the run ended | failed if the supervisor gave up; otherwise stopped, exited (your program ended), failed (a start failed or was refused) or crashed (the VM ended without a stop) |
| 12 | Neither runs, and the run didn't end | crashed: "its supervisor ended without recording why", or "not running since the host restarted" if the run was in an earlier boot |
Reading cairn ps
$ cairn ps
APP ROLE STATE HEALTH TIME RESTARTS ENDPOINTS MACHINE
run-claude-cairn-8a1f96 current stopped - ended 145h 46m ago 0 - UY5DURWY3K
run-claude-e4-213865 current crashed - - 0 - D69JCGAMRW- ROLE is
currentfor the app's VM. During a rollback, the new VM being removed also appears, asnew. - TIME is how long it has been up, or how long ago it ended.
- ENDPOINTS are the published ports from the last confirmed configuration. They aren't a live reachability check.
Useful options:
cairn ps --apps # one row per app
cairn ps --state running,held # filter by state
cairn ps --health unhealthy # filter by health
cairn ps --verbose # add a NOTES column explaining each state
cairn ps -q # names only, for scriptscairn ps only lists VMs that cairn's records know about. A Firecracker process of yours that no record mentions is reported by cairn doctor instead.