Keep print jobs on disk in state.dir

Breaking: with state.dir set, jobs still waiting when the daemon stops
or crashes print after the next start, in order and however old,
instead of being marked failed or forgotten; a client that resends such
jobs must stop. The Docker image sets state.dir, so a container keeps
its jobs in /var/lib/uberbringer, and loses them with the container
unless a volume is mounted there.

The owner decided that jobs survive a restart and that a restart never
prints a receipt twice. When state.dir is set, the daemon now opens the
SQLite job store there, jobs.db, and the queue restores it before the
subscriptions are made and before anything is served, so restored jobs
go ahead of new ones and a second daemon on the directory stops before
it reads the subscriptions' state. Without state.dir the queue keeps its
jobs in memory, as before. The store closes once the queue has stopped.

A job's sending mark is synced before its first byte, so one caught mid
write reads uncertain after the restart and is never sent again; a job
that had not reached the printer prints once. A store that cannot be
opened stops the start with an error naming the file, rather than
starting empty and forgetting which receipts are in doubt.

The unit gains UMask=0077, so the store's files are its user's alone,
and says why systemd's 90 s stop timeout is enough; the Dockerfile and
docs/docker.md ask for --stop-timeout 40. design.md replaces "The queue
lives in memory" with the store, the state machine, the sync policy,
store failures, stage 1a's numbers, and that the ARM builds ship the
store untested on ARM hardware. install.md and docker.md say how to set
aside a store that will not open; configuration.md, api.md, cli.md and
ntfy.md say what survives a restart. The license notices gain the
driver's modules.

TestServeRestart runs the daemon twice on one directory: jobs queued
when the first run stops, its printer refusing connections, print in
order after the restart, ahead of a new job, and a job seeded in sending
between the runs reads uncertain and never reaches the printer.

Part of stage 1d of docs/plans/job-store.md (decisions 14 and 15).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
57_WolveandClaude Opus 5.5 committed 2026-12-01 16:48:57 -06:00
1 parent 341353f702
commit 5cc4614ad7
20 files changed
+5144 -93

No files matched your search

+30 -4
View File
@@ -13,12 +13,18 @@ version may break callers; such changes are listed under **Breaking**.
while it was sending the job to the printer, so the receipt may have
printed. Such a job is never sent again. Clients that switch on `status`
must handle it.
- The Docker image sets `state.dir`, and the daemon now checks at start
that it can write there, with or without ntfy subscriptions, so a
container that cannot write `/var/lib/uberbringer` no longer starts:
- With `state.dir` set, jobs still waiting when the daemon stops print
after the next start, in order and however old, instead of being marked
failed; after a crash they print too, instead of being forgotten. A
client that sends a failed job again at shutdown, or after a restart,
must stop doing so, or the receipt prints twice. Without `state.dir`
nothing changes. `install.sh` writes `state.dir` into new configs.
- The Docker image keeps its job store in `/var/lib/uberbringer`, its
`state.dir`, so a container that cannot write there no longer starts:
one started with `--read-only` and no volume there, or with a bind mount
owned by root. Mount a named volume there, or a directory owned by
`10001:10001` (`docs/docker.md`).
`10001:10001`, and stop the container with `--stop-timeout 40` so a
receipt being written can finish (`docs/docker.md`).
- A job with a `raw` element prints only with a token issued with
`uberbringer token --raw`. Every other token, every token issued so far
included, gets `403` `token_scope` for it and keeps every other route.
@@ -34,6 +40,26 @@ version may break callers; such changes are listed under **Breaking**.
### Added
- Jobs survive a restart. With `state.dir` set, every job is kept in a job
store there, `jobs.db`, a SQLite database through the pure-Go
`modernc.org/sqlite`, and every kept status answers after a restart.
- A restart never prints a receipt twice: each attempt is recorded on
disk before its first byte goes to the printer, and a job caught
sending reads `uncertain` and is never sent again. Each job costs one
synced write, plus one per failure and per ntfy job; a job accepted
over HTTP can be lost to a power cut within about 30 seconds of its
`202`, but is never printed twice.
- A store that cannot be opened stops the daemon with an error naming
the file; `docs/install.md` and `docs/docker.md` say how to set it
aside. Only one daemon can use a state directory.
- The store holds what the receipts print. Its files are readable by the
daemon's user only, and the systemd unit gains `UMask=0077`.
- The armv6, armv7 and arm64 release builds ship the store untested on
ARM hardware. CI now cross-compiles the ARM targets on every push.
- Going back to 0.2.0 needs every key added since removed from the
config, such as `[state]`, `queue.content_bytes`, `printer.cut_feed`
and the `ntfy` tables: 0.2.0 refuses them as unknown. It never reads
`jobs.db`, so the jobs waiting there do not print.
- Notifications:
- The `notify` module prints a card from
`{"title", "message", "priority", "tags"}`, with `topic`, `click`,