Lifecycle
This page covers what happens to a machine from cairn deploy to cairn destroy: how a deploy replaces the running machine and what it does when something fails, what the states in cairn ps and cairn status mean, when cairn restarts a workload, health checks, how a stop works, pause and resume, start at boot, and cairn exec. Key syntax for cairn.toml is in manifest; every flag is in cli.
The short version
cairn deploybuilds the new machine while the old one still runs, then stops the old one, starts the new one and waits until it is ready, and deletes the old one. An app has one machine at a time, so clients see a short gap. If the new machine fails, the old one is started again.- A deploy that was killed (a crash, a second Ctrl+C, a power loss) is settled by the next
cairn deploy,start,stopordestroyof the app. Settling never starts a machine, so the app can stay down until you run one of them. - For an app with volumes, a failed deploy may instead hold the old release, because the new one may have changed its volumes. See volumes.
- If the workload ends, cairn restarts it on a delay that grows with each failure.
cairn stopsends your workload a signal, waits, then kills the VMM. It keeps disks and the network, socairn startcan boot the same machine again.
Deploying
cairn deploy # reads ./cairn.toml
cairn deploy --dry-run # shows the resolved settings and deploys nothingA deploy runs these steps, in this order:
- Lock and settle. It takes the app's lock and settles any earlier attempt that did not finish (see Interrupted deploys).
- Prepare. It claims or creates the app's network and gets the image (pulled, or built from
[build]). - Build the machine. A new root disk, a config drive, and the machine's records. The old machine still runs.
- Stop the old machine and confirm it has exited, then make the new one the app's current machine. A delayed start of the old one is refused from here on.
- Boot the new one. As it attaches to the app's network it takes the app's address and publishes its ports (ports you removed are unpublished). Then the deploy waits for the guest to report that the workload started.
- Wait for readiness (below).
- Accept and clean up. The new release is the deployment, and the old machine is deleted.
The deploy records each step in apps/<app>/deploy.json before it acts: building (steps 2 and 3), stopping (step 4's stop), starting (from the moment the new machine is current to its readiness), accepted (step 7), and rolling-back while a failure puts the old machine back. The file is removed when the deploy is done. While it is there, cairn status shows what the deploy is doing, with its pid.
A new deploy of an app always makes a new machine with a fresh root disk. Anything written to the root disk is gone after the next deploy. Put data that must stay on a volume.
Readiness
Before it accepts the new machine, cairn waits until:
- every TCP
internal_portin your[[services]]accepts connections, and - every
[checks.<name>]you defined passes (see Health checks).
The wait has a deadline, --wait-timeout (default 60 s, from 1 s to 1 h). --no-checks skips the wait. Health checks still run afterwards. An app with no services and no checks is ready as soon as the workload starts.
Example from an nginx deploy on this host: the deploy reports ready about one second after the workload starts.
The new machine serves its ports as soon as its workload listens, before it is ready: a client can reach it during the whole wait. If it then fails its checks, the deploy rolls back, and those clients were served by the release that was rolled back.
Failure and rollback
| Failure happens | Result |
|---|---|
| Before the old machine is stopped (image, build, Ctrl+C) | The new machine is deleted. The old release keeps serving and is not touched (previous_preserved). |
| While the old machine is stopping, or after it (boot, readiness timeout, Ctrl+C) | The deploy rolls back: the old machine is made current again and started (previous_running, or previous_starting if it is not ready in time), and the new machine is stopped and removed, except its logs, which stay until the next successful deploy. For an app with volumes the old release may be held instead (previous_held): see volumes. An old machine that was already stopped before the deploy stays stopped (previous_stopped). |
| After the new release is accepted | It is the deployment, and the deploy succeeds. Cairn finishes the cleanup; anything it could not confirm is reported and kept so the next command can finish it. |
The first Ctrl+C cancels the deploy, which then deletes the new machine or rolls back as above; a Ctrl+C during the rollback is ignored. A second Ctrl+C exits at once and leaves the attempt recorded (left_for_next_command). The outcome values are listed in cli.
Interrupted deploys
A deploy that did not finish leaves deploy.json behind: it was killed, the host lost power, or you pressed Ctrl+C twice. The next cairn deploy, cairn start, cairn stop or cairn destroy of the app settles it first, under the app's lock, and says so:
an earlier deploy of web did not finish (it was starting machine 4N8KDQ2W7R); settling it
rolling back: machine YJ449SSML5 is current again| Recorded state | Settling does |
|---|---|
building, stopping | Deletes the new machine, which never ran. The old machine stays as it is. |
starting, rolling-back | Rolls back: the old machine is current again (or held, for an app with volumes), the new one is stopped and removed (its logs stay until the next successful deploy). While rolling-back is recorded, the new machine never boots: not from a crash restart, systemd, or cairn start. |
accepted | Finishes the cleanup: the new machine stays current. |
Settling never starts a machine. The command then does its own work: start starts the current machine, deploy goes on with its own attempt, stop stops, destroy destroys. So a deploy killed while it was stopping the old machine or starting the new one leaves the app down until you run cairn start <app> or deploy again. That includes a host restart: after a power loss while the new machine was starting, the app does not come back at boot, because its current machine is the new one, which is not set to start at boot until the deploy accepts it (a power loss while the old machine was still current boots the old one as usual). Run cairn start <app> after the reboot; it does nothing if the app is already running.
cairn pause, resume, status, ps, exec and the cairn volume commands do not settle. pause, resume and every cairn volume command that works on a volume (extend, repair, backup, restore, destroy) refuse while an unsettled attempt is recorded, and name the commands that settle it; exec runs in the current machine if it is running.
If settling cannot finish (the new machine would not stop, for example), deploy.json stays, and cairn start and cairn deploy refuse with Unsettled; cairn stop <app> stops the machines and settles it. When only cleanup is left (a unit or a directory that could not be removed), cairn status says "cleanup left" and the next deploy retries it; nothing is refused, except that a start-at-boot setting the deploy could not apply makes the next deploy refuse until it is applied (see troubleshooting). cairn doctor lists each app with an attempt that did not finish. See troubleshooting.
A deploy that changes allow gives the new list to the new machine. See networking.
States
cairn ps and cairn status <app> show one state word per machine. Cairn works it out from the machine's records first, then from whether the processes they name still run: the run file the supervisor writes, then whether its supervisor and its VMM are alive (same pid, same start time, this host boot), then the VMM's process state in /proc and its cgroup's freezer. Status asks neither the VMM nor systemd, so it answers at once even for a stopped VMM.
The first row that matches wins:
| # | Condition | State |
|---|---|---|
| 1 | A record of the machine cannot be read, whether its supervisor or VMM runs cannot be confirmed, or its running VMM's cgroup freezer cannot be read | unknown (with the file or the reason) |
| 2 | No run file | stopped ("never started"), or none for an app with no machine |
| 3 | The VMM runs and is stopped by a signal (T/t in /proc) or its cgroup is frozen | frozen |
| 4 | The VMM runs and the run file records a pause | paused |
| 5 | The supervisor runs and is preparing, booting or waiting for its network | starting |
| 6 | The supervisor runs, its run says running, and the VMM runs | running |
| 7 | The supervisor runs and the VMM has ended, or a stop is under way | stopping |
| 8 | The supervisor runs and is waiting to restart the workload | restarting |
| 9 | The supervisor runs and the run has ended (it is finishing) | the ending's word, as row 11 |
| 10 | The supervisor has ended and the VMM runs | unsupervised |
| 11 | Neither runs and the run ended | failed if the supervisor gave up; else stopped, exited (the workload ended), failed (a start failed or was refused) or crashed (the VMM or the guest ended without a stop) |
| 12 | Neither runs and the run did not end | crashed: "its supervisor ended without recording why", or "not running since the host restarted" when the run was in an earlier boot |
| State | Meaning |
|---|---|
running | The guest's command is running. |
starting | Preparing, booting, or waiting behind its network. |
stopping | A stop is under way. |
paused | Paused with cairn pause, or through the VMM's API socket. |
frozen | Its VMM is stopped by a signal, or its cgroup is frozen (systemctl --user freeze). cairn resume releases it. |
restarting | The workload ended and the supervisor is waiting to start it again. |
stopped | A stop completed, or it never started. |
exited | The workload ended and it was not restarted. |
crashed | The VMM or the supervisor ended without a requested stop. Under systemd, a supervisor that was killed reads crashed for about a second, until systemd starts a new one. |
failed | A start failed, or the supervisor gave up restarting. |
unsupervised | The VMM runs but its supervisor does not. cairn stop stops it. |
unknown | Cairn cannot tell. It never claims anything is alive or gone that it could not confirm. |
held | ps only: the app's last deploy failed after the new release may have changed its volumes, and nothing will boot it. See volumes. |
cairn ps lists the machines the records name: each app's current machine and, during a rollback, the new machine (ROLE new) until it is removed. A Firecracker process that no record names is not listed; cairn doctor reports it.
cairn ps columns are APP, ROLE, STATE, HEALTH, TIME, RESTARTS, ENDPOINTS and MACHINE. Real output from this host (for machines that are not running):
$ 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 - D69JCGAMRWUseful filters: cairn ps --state running,held, --health unhealthy, --apps (one row per app), -q (identifiers only), --verbose (details and warnings). HEALTH - means no verdict.
cairn status <app> adds the network row, restart history, health results and log paths. A machine that runs with no network (its network agent died under a direct-launched machine) shows as running (no network). Cairn does not restart it behind your back: run cairn stop <app> && cairn start <app>.
Restarts
By default cairn restarts a workload that fails. Configure it in the manifest:
[restart]
policy = "on-failure" # "never" | "on-failure" (default) | "always"
max_restarts = 10 # optional: give up after this many in a row (up to 10000)| Policy | Restarts after |
|---|---|
never | No workload ending. |
on-failure | A non-zero exit, a signal (including an OOM kill), a guest panic or reset, a silent guest, a failed restart-check. Not a clean exit 0. |
always | Every ending, a clean exit included. |
Under every policy, a failure of the VMM itself (the Firecracker process dies) is recovered. A command that cannot start (the image's command is not found, the configuration is refused) is not restarted, because starting again does not fix it. A stop you asked for is never restarted.
Backoff
Each restart in a row waits twice as long as the last:
| Restart in a row | Delay |
|---|---|
| 1 | 1 s |
| 2 | 2 s |
| 3 | 4 s |
| 4 | 8 s |
| 5 | 16 s |
| 6 | 32 s |
| 7 and after | 60 s (the cap) |
A boot that runs for 2 minutes without ending resets the count. A paused machine counts as running for this. If max_restarts is reached, the supervisor gives up and the unit ends failed. cairn ps shows the count in RESTARTS and cairn status lists the last ten endings, so a crash loop is visible.
A restart reuses the saved machine spec and disk. It never reads your shell, .env or manifest again: only a deploy does that.
Silent guests
The guest sends a heartbeat. If none arrives for 45 s while the supervisor was running, cairn asks the VMM whether the guest is still running. If it answers Running for 3 more seconds with no heartbeat, the guest is treated as hung, the VMM is killed, and the restart policy decides what happens next.
Health checks
Checks are defined per app and run inside the guest. Each is one of http, tcp or exec:
[checks.web]
http = "/healthz" # GET; any 2xx passes unless `status = [...]` lists codes
# port = 8080 # needed when the app has no or several TCP services
interval = "10s"
timeout = "2s"
failures = 3
grace = "30s"
on_failure = "report" # or "restart"Defaults: 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). At most one of http, tcp, exec per check. on_failure = "restart" needs failures of at least 2 and a restart policy other than never. The full key list is in manifest.
A failing check does not count while the workload is younger than grace and the check has not yet passed once; the first pass ends the grace, and failures count from then on. Health shown in ps and status is one of healthy, starting, unhealthy, unknown or - (no checks, or not running). A result that is too old to trust shows unknown, never a stale healthy.
With on_failure = "report", a failing check changes the health word and nothing else. With "restart", failures failures in a row kill the VMM and the restart policy applies.
Stopping
cairn stop web
cairn stop web --timeout 60smachine YJ449SSML5 stopped
`cairn start web` boots it again with its disk as it is
the stopped app still holds tcp://127.0.0.1:8080; `cairn start web` brings it back, `cairn destroy web` releases themA stop does this:
- The host asks the guest to shut down. The guest's init sends the workload its stop signal.
- The workload has a grace period (10 s by default) to exit. After it, init sends SIGKILL.
- Cairn waits for the VMM to exit. If it has not exited within the stop timeout, cairn sends SIGKILL to it and waits up to 10 s more.
The signal is, in order: kill_signal from your manifest, the image's own StopSignal (for example SIGQUIT for nginx, SIGINT for postgres), else SIGTERM. Set both per app:
kill_signal = "SIGINT"
kill_timeout = "30s" # 1s to 5mSIGKILL, SIGSTOP, SIGCHLD and the job-control signals are refused. The stop timeout (the wait before cairn kills the VMM) is 20 s by default, or kill_timeout plus 10 s when that is longer. cairn stop --timeout overrides it, up to 310 s. cairn start and the deploy's own stop use the same rule.
A stop keeps the disks, the network and the volumes. cairn start <app> boots the same machine again (--wait, default 250 s, is the startup deadline; it does not wait for readiness). cairn destroy <app> removes the machine's disks and records and keeps the network. It also keeps volumes unless you pass --volumes.
For apps made by cairn run, stop and destroy also sync the agent's work first. See run.
Pause and resume
cairn pause web
cairn resume webmachine YJ449SSML5 paused; it keeps its memory and its ports. New connections to a 127.0.0.1-published port are reset after about 3 s while it is paused (cairn-netd's proxy). `cairn resume web` continues it
machine YJ449SSML5 runningPause freezes the guest's CPUs. Memory and published ports are kept. While paused, the host still accepts connections on the published port but the guest does not answer: on this host, a new connection to a 127.0.0.1 port was reset after about 3 s. Resume continues where it stopped. A machine that is stopped needs cairn start, not resume. Pausing a machine that is not running is refused.
cairn pause asks the machine's supervisor, which pauses the VMM, confirms it with the VMM, and records the pause in the run file; that record is what cairn status shows as paused. The command waits up to 5 s for the supervisor's answer. A pause is refused while the supervisor is between boots or stopping the machine, and while a deploy of the app is under way or did not finish. A pause made directly through the VMM's API socket is recorded too, once the supervisor's silence check asks the VMM (up to about 45 s later; until then status says running), and a resume made that way is noticed within a second or two of the guest's next heartbeat. A new boot always starts unpaused.
cairn resume also releases a machine that is frozen: it sends SIGCONT to a VMM stopped by a signal, and runs systemctl --user thaw for a machine whose unit was frozen with systemctl --user freeze (a direct-launched machine has no unit; resume names its cgroup instead). A machine that was frozen and paused is released and then resumed in one command. A VMM held by a debugger is left alone.
Start at boot
A machine started through systemd (the default launcher where systemd is available) lives under your user manager. It starts again at host boot only if your user has linger on:
loginctl enable-linger $USER
cairn doctorWithout systemd, or with --launcher direct, a machine runs as a plain process and does not come back after a reboot. Machines that you stopped stay stopped. A machine whose app is held is not booted either. See getting started for the install steps.
Exec and console
cairn exec web -- ls -la /etc
cairn exec -i web -- cat < file
cairn exec -it web -- sh # interactive terminal
cairn console web # the same, picking a shell for youA real session: cairn exec web -- sh -c 'echo hi from $(hostname); cat /proc/1/comm' prints hi from web and cairn-init and exits 0, and cairn exec web -- sh -c 'exit 7' exits with status 7. cairn console web on a terminal starts with:
cairn: connected to web (machine 5YE8WELG3J) as root. Type ~. to disconnect, ~? for help.
root@web:/#cairn exec runs a program inside a running machine through the guest agent. There is no implicit shell: use sh -c '...' for pipes and globbing. The command inherits the workload's user, directory and environment unless you set -u, -w or -e KEY=VALUE. Without -i the command's stdin is at EOF. With -t you get a guest terminal; -it needs a real terminal on your side and enables the ~. escape (disconnect) and ~? (help).
Exit status: the command's own code, 128+N if a signal ended it, 125 if cairn refused the request and nothing ran, 126 cannot run, 127 not found, 255 unknown result. A guest allows 8 exec sessions at a time. Processes started by a session end with it.
cairn console tries $SHELL (if absolute), then /bin/bash, /bin/sh, /bin/ash; --shell forces one. Exec needs the guest kernel to have cgroup.kill; a kernel without it boots with exec disabled and says so on the console.
Memory
[vm] memory is the guest's RAM ceiling. It is not a reservation: the host allocates pages as the guest touches them. By default the machine has a balloon device with free page reporting, so memory the guest frees returns to the host within seconds. Page cache stays, free blocks under 128 KiB stay, and memory a program frees into its own allocator pool stays. Re-touching returned memory costs a host page fault per page. A workload that frees and reallocates large buffers repeatedly can opt out with [vm] balloon = false. A deployed app gets the device at its next deploy. See manifest for cpus, memory and rootfs_size.
How it works
The supervisor is a small per-machine process that owns the VMM. It boots the guest, reads the guest's events over vsock, applies the restart policy and writes a run file that ps and status read. systemd (when used) restarts the supervisor itself if cairn's own machinery fails, using exit codes: 0 done, 1 machinery failed (restart), 64 cannot start (do not restart), 65 gave up (do not restart). Boot has deadlines: 30 s to the guest's first message and 10 s from there to the workload starting. See architecture.