Skip to content

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:

VariableEffect
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=0No colour, unless CLICOLOR_FORCE is set.
TERM=dumbNo colour and no live progress. doctor still prints its summary.
TERM unsetNo live progress. Colour only if CLICOLOR, CI or CLICOLOR_FORCE is set.
CAIRN_PROGRESS=plainPrint progress as plain lines instead of redrawing. Only this exact value works.
A locale that isn't UTF-8Plain 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.

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

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

sh
cairn access --json
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:

json
{"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, kind and name. For a custom file: kind, version, sha256, from, size, config_checked and reused.
  • deploy.warnings, including warnings about a custom kernel.
  • With volumes: volumes, detached_volumes and kill_signal (signal and source).
  • 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 --json includes vm.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 --json includes machine.kernel and machine.volumes. While the app is held, it also includes hold.
  • While a deploy is unfinished, status --json includes deploy: its state, machine, previous, holder_pid, deploying (whether its process is alive), since_unix, sentence, machine_state, machine_detail, rollback, cleanup_only, cleanup (what's left) and logs.
  • ps --json has an apps array. Each VM in it includes its log paths, console_tail and kernel.
volumes, stop and run
  • Each entry in volumes has name, id, size, host_allocation, destination, created, and a state_note when something is unfinished or damaged.
  • Every cairn volume command accepts --json.
  • A stop --json that finished an interrupted deploy by rolling it back includes hold_decided: the action (restore or hold), its evidence, and the hold the app is left with.
  • cairn run --status --json is described in Run an agent.

Exit codes ​

CodeMeaning
0Success.
1The command failed.
2Wrong usage (a bad option or argument). Under --json, the error is JSON too.
125Refused 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.
130Interrupted 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.