Core concepts

Six ideas explain almost everything sg does, and everything it refuses to do.

Specs

A spec is a YAML file that says what should exist. There are three kinds, all api_version: genesis/v1:

SpecDescribesCommands
machine.yamlOne hardened LXD hostsg machine …
cluster.yamlAn LXD cluster over three or more machinessg cluster …
application.yamlInstances, volumes, services and a load balancer on a clustersg application …

Specs are strict. Unknown or wrongly typed fields are refused, names must be lowercase DNS-safe labels, and every field you leave out has a documented default. Secrets never go in a spec. A spec names the environment variable that holds the secret, and sg reads it at run time.

The project directory

Keep every spec for one estate in one directory. The ledger lives next to them at .sg/state.db. The cluster reads its members' machine records from that ledger, and the machine destroy guard reads the cluster's. A spec in another directory gets another ledger, and the two can't see each other.

~/estates/lab/
├── node-a.yaml
├── node-b.yaml
├── node-c.yaml
├── cluster.yaml
├── application.yaml
└── .sg/state.db        # the ledger: never edit it by hand

Plans

A plan is the ordered list of changes needed to make reality match the spec. Each change has an ID (harden.ssh, cluster.join.node-b, volumes.pgdata), a reason, and a risk grade:

RiskMeans
noneVerification only. Runs no host mutation.
lowThe least disruptive kind of change.
mediumChanges how the host or an instance behaves, or creates data storage.
highCan cut access, interrupt service or recreate an instance. Read these rows twice.

An application group takes the grade of its most severe replica change, so an image change that recreates instances grades the whole group high.

plan commands are read-only. They connect, observe and print. Apply commands always build their own fresh plan, so an old plan you looked at an hour ago is never trusted.

Runs and confirmation

An apply is a run. It prints the plan and asks … [y/N]:. Only an answer starting with y continues.

  • --yes skips that question. It never skips a safety or ownership check.
  • A run stops at the first failed change and records it. Fix the host and run again; sg picks up from what's actually there.
  • Ctrl-C cancels cleanly. No new change starts, cleanup runs, and the run is recorded as aborted.

The ledger and ownership

Everything sg changes goes into the ledger: which change, on which host, with which inputs, and what it created. That record is the only proof of ownership sg accepts.

So rollback and destroy act only on what the ledger proves sg made. A container you created by hand on the same host, a volume another tool made, a package that was already installed: all retained and reported, never touched.

retained: instance scratch-box is not owned by sg

Don't edit or delete state.db. Back it up with your specs instead.

Generations

For applications, every deploy that finishes and passes health and exposure checks becomes a generation: 1, 2, 3, and so on. Failed or aborted deploys stay in run history but never become generations.

sg application rollback redeploys the exact recorded spec of generation N-1 as a new generation N+1. History only grows.

Exit codes

CodeMeans
0Success, help, a read-only report (even one that shows drift), or you answered N
1Runtime failure, safety refusal or configuration error
2Usage error: bad flag, unknown group or verb