docs · pre-release
Menu
Configuration / The KV store

The KV store

Three files already configure everything shep runs: a Flockfile for a sheep, shep.toml for the shepherd, dogs.toml for its dogs. None has a field for "the port the last on-call engineer picked" or a feature flag a provisioning script leaves behind. The KV store is what's left over: a flat, file-locked junk drawer, explicitly not the primary config path.

note
Reaching for this to configure a sheep? Put it in the Flockfile. A dog? Put it under [<name>] in dogs.toml. This store is what's left after those two.

The three verbs

shep kv set <key> <value> writes a key, replacing whatever was there. shep kv get <key> prints one value; shep kv get with no key lists everything. shep kv unset <key> removes one key; shep kv unset --all empties the store: a flag, not a key named all, because shep kv unset all would mean something different depending on your own store.

The old spelling

There is none. shep get, shep set and shep unset read, write and undo a sheep's or a dog's settings, and none of them reaches this store. Ashep set feature.flag on is refused as a name no sheep or dog is, and the sentence names shep kv set.

Real output

Run against a fresh $SHEP_HOME, no shepherd listening:

$ shep kv set bark.cooldown 30s
KEY            VALUE
bark.cooldown  30s

$ shep kv set feature.flag on
$ shep kv get
KEY            VALUE
bark.cooldown  30s
feature.flag   on

$ shep kv get nope.key
error[not_found]: `nope.key` is not set
$ echo $?
3

$ shep kv unset bark.cooldown
REMOVED
1
$ shep kv unset --all
REMOVED
1
$ shep kv get
KEY  VALUE

A key that was never there answers NotFound on both kv get and kv unset, exit 3 either way: a script can write shep kv get feature.flag || echo default and trust the exit code.

The key grammar

A key is [A-Za-z0-9._-], one to 128 bytes, and can't start with a dot. A dot is part of a name, not a path: bark.cooldown is one flat key, not a nested object, and shep kv get bark won't find it. A nesting grammar here would be a second config language, with its own quoting rules. A value is a string, capped at 4 KiB: the store is read whole on every access, and the cap keeps kv.json from becoming a blob store.

A sheep's own settings are not in this store: shep copy moves one, over the socket, because it reads what the running flock holds, shep set changes one the same way, and shep unset drops it again.

No shepherd required

shep kv get/set/unset never touch the socket: they read and write $SHEP_HOME/kv.json directly, the same way shep enable writes shep.toml with nothing listening. That makes it usable during provisioning, before any shepherd boots. A dog reads it the same way, through shep_core::kv: a 0600 file in a 0700 $SHEP_HOME already has every property a socket round trip would have bought.

Concurrent writers lose nothing

Two shep kv set invocations racing (two provisioning scripts, or an operator and a dog) are serialized by an exclusive advisory lock on a sibling kv.json.lock. The loser waits its turn. The file itself is written through a BTreeMap, so keys stay sorted and two writes of the same content are byte-identical: keep it in a dotfiles repository, git add and diff it like any other small config file. Mode is 0600.