Output and scripting
How cairn's output differs between a terminal and a script, its JSON output, and its exit codes.
Terminal and pipe output
On a terminal, cairn uses colour, redraws its progress lines in place, and doctor shows a summary. When output goes to a pipe, a file or --json, you get plain text instead: no colour, no redrawing, and the same words and layout every time.
You can change this with environment variables:
| Variable | Effect |
|---|---|
NO_COLOR (any non-empty value) | No colour. Live progress still works. |
CLICOLOR_FORCE (any non-empty value) | Colour even into a pipe (never in --json), unless NO_COLOR is set. |
CLICOLOR=0 | No colour, unless CLICOLOR_FORCE is set. |
TERM=dumb | No colour and no live progress. doctor still prints its summary. |
TERM unset | No live progress. Colour only if CLICOLOR, CI or CLICOLOR_FORCE is set. |
CAIRN_PROGRESS=plain | Print progress as plain lines instead of redrawing. Only this exact value works. |
| A locale that isn't UTF-8 | Plain ASCII symbols and spinner. cairn uses the first non-empty one of LC_ALL, LC_CTYPE and LANG. |
NO_COLOR always wins. The decision is made separately for standard output and standard error.
cairn deploy 2>deploy.log # plain progress lines in the log
CAIRN_PROGRESS=plain cairn deploy # for a screen reader, or a recording
CLICOLOR_FORCE=1 cairn ps | less -R # colour through a pipeNarrow terminals
If you make the terminal narrower during a long live line, terminals that re-wrap lines (tmux, VTE, kitty) can leave one stale line above the new output. Nothing is lost.
JSON
Every command accepts --json. Standard output is then a single JSON document and nothing else. It is never coloured.
cairn access --json{"allowed":true,"answer":"allowed: work is in the cairn group's member list","names":[{"member":true,"name":"work","padded":[],"primary":false}],"ok":true,"reason":null,"uid":1001}A failure looks like this:
{"ok": false, "code": "...", "message": "..."}Branch on code in scripts. The message is meant for people and may change.
Useful fields
deploy
deploy.kernel: for the pinned kernel,kindandname. For a custom file:kind,version,sha256,from,size,config_checkedandreused.deploy.warnings, including warnings about a custom kernel.- With volumes:
volumes,detached_volumesandkill_signal(signalandsource). - On a redeploy,
stop_to_ready_s: seconds from the start of the old VM's stop to the new one being ready. deploy --dry-run --jsonincludesvm.balloon.
A failed deploy's JSON adds step, outcome (see the outcome table), machine (the new VM), logs, leftovers, kernel, warnings, the volumes, the previous VM and the next command to run. It includes guest_panic and vmm_error when the console explains the failure. A deploy that succeeded but couldn't finish cleaning up exits 0 with outcome: deployed_cleanup_pending.
status and ps
status --jsonincludesmachine.kernelandmachine.volumes. While the app is held, it also includeshold.- While a deploy is unfinished,
status --jsonincludesdeploy: itsstate,machine,previous,holder_pid,deploying(whether its process is alive),since_unix,sentence,machine_state,machine_detail,rollback,cleanup_only,cleanup(what's left) andlogs. ps --jsonhas anappsarray. Each VM in it includes its log paths,console_tailandkernel.
volumes, stop and run
- Each entry in
volumeshasname,id,size,host_allocation,destination,created, and astate_notewhen something is unfinished or damaged. - Every
cairn volumecommand accepts--json. - A
stop --jsonthat finished an interrupted deploy by rolling it back includeshold_decided: theaction(restoreorhold), itsevidence, and theholdthe app is left with. cairn run --status --jsonis described in Run an agent.
Exit codes
| Code | Meaning |
|---|---|
0 | Success. |
1 | The command failed. |
2 | Wrong usage (a bad option or argument). Under --json, the error is JSON too. |
125 | Refused before anything ran (exec, console, run, net, and a deploy's pre-flight checks). exec, console and run also use it for wrong usage, so it can't be confused with the program's own exit code. |
130 | Interrupted with Ctrl+C. |
exec, console and run otherwise pass through the program's own exit code. The full table, by command, is in Command line: exit status.