Skip to content

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:

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)
PolicyRestarts when your program…
nevernever
on-failureexits 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.
alwaysends 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 row1234567 and after
Wait1 s2 s4 s8 s16 s32 s60 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.

toml
[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:

KindExamplePasses when
httphttp = "/healthz"A GET request gets a 2xx response, or one of the codes listed in status = [...].
tcptcp = 5432The port accepts a connection.
execexec = ["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 in cairn ps changes to unhealthy. Nothing else happens.
  • With on_failure = "restart", after failures failures in a row cairn kills the VM, and the restart policy decides what happens next. This needs failures of at least 2 and a restart policy other than never.

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?

SettingDefaultAllowed
interval10 s1 s to 1 h
timeout2 s100 ms up to interval
failures31 to 10
grace30 s0 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 ​

HealthMeaning
healthyEvery check passes.
startingStill within the start-up grace period.
unhealthyA check has failed failures times in a row.
unknownThe 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:

StateMeaning
runningYour program is running.
startingPreparing, booting, or waiting for its network.
stoppingA stop is in progress.
restartingYour program ended, and cairn is waiting to start it again.
pausedPaused with cairn pause.
frozenIts process was stopped by a signal, or its systemd unit was frozen. cairn resume releases it.
stoppedStopped on purpose, or never started.
exitedYour program ended, and the restart policy didn't restart it.
crashedThe 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.
failedIt couldn't start, or cairn gave up restarting it.
unsupervisedThe 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.
unknowncairn can't tell. It never claims something is running or gone unless it has checked.
noneThe 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:

#ConditionState
1A 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 readunknown, with the reason
2No run filestopped ("never started"), or none for an app with no VM
3The VM process is stopped by a signal (T/t in /proc), or its cgroup is frozenfrozen
4The VM process runs, and the run file records a pausepaused
5The supervisor runs, and is preparing, booting or waiting for the networkstarting
6The supervisor runs, the run file says running, and the VM process runsrunning
7The supervisor runs, and the VM process has ended or a stop is under waystopping
8The supervisor runs, and is waiting to restart your programrestarting
9The supervisor runs, and the run has ended (it is finishing)the ending's state, as row 11
10The supervisor has ended but the VM process runsunsupervised
11Neither runs, and the run endedfailed 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)
12Neither runs, and the run didn't endcrashed: "its supervisor ended without recording why", or "not running since the host restarted" if the run was in an earlier boot

Reading cairn ps ​

console
$ 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 current for the app's VM. During a rollback, the new VM being removed also appears, as new.
  • 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:

sh
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 scripts

cairn 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.