Files
57_WolveandClaude Opus 5.5 5cc4614ad7 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>
2026-12-01 16:48:57 -06:00

4.6 KiB

Running in Docker

The image built from the root Dockerfile is a microservice for running behind your own reverse proxy. It contains no proxy and no TLS: it serves plain HTTP on port 8080, and the proxy terminates HTTPS.

docker build -t uberbringer .
docker run -d -p 127.0.0.1:8080:8080 --stop-timeout 40 \
  -v "$PWD/config.toml:/etc/uberbringer/config.toml:ro" \
  -v uberbringer-state:/var/lib/uberbringer uberbringer

The examples publish the port on the host's loopback address only, for a proxy on the host; a proxy in another container reaches it over a shared Docker network instead, with no -p at all. Publish port 8080 only to the proxy, never directly to the internet.

The config

In the mounted config.toml (configuration.md):

  • Set bind_ip = "0.0.0.0" in [webserver].
  • Set trusted_proxies to the address the proxy's requests come from: its container network (e.g. ["172.18.0.0/16"]), or for a proxy on the host, the Docker bridge's gateway (usually 172.17.0.1). Have the proxy set X-Real-IP to the client's address. Otherwise every request appears to come from the proxy, and all clients share one rate limit.
  • Let the proxy pass request bodies up to webserver.body_limit (4 MiB by default).

The settings can come from environment variables instead. To run without a config file, set UBERBRINGER_CONFIG empty and put the variables in an env file that only you can read (chmod 600 uberbringer.env), so the secret stays off the command line:

UBERBRINGER_CONFIG=
UBERBRINGER_WEBSERVER_BIND_IP=0.0.0.0
UBERBRINGER_WEBSERVER_TRUSTED_PROXIES=172.18.0.0/16
UBERBRINGER_API_SECRET=<the output of uberbringer secret>
UBERBRINGER_PRINTER_ADDRESS=192.168.1.245
docker run -d -p 127.0.0.1:8080:8080 --stop-timeout 40 --env-file uberbringer.env \
  -v uberbringer-state:/var/lib/uberbringer uberbringer

Health checks

For container health checks, use GET / to see whether the daemon is up. /healthz answers 503 while the printer is unreachable, so it suits alerting better than restarting the container.

The state directory

The image sets state.dir to /var/lib/uberbringer, where the daemon keeps its job store, jobs.db, so that waiting jobs print after a restart, and where the ntfy subscriptions keep their state. The daemon does not start if it cannot write there.

  • Mount a named volume there, as the examples do. A new container, after a pull or an upgrade, then takes over the jobs and the subscriptions' state. Without a volume they live in the container and are lost with it, and a container started with --read-only does not start at all. The image declares no VOLUME, so a container never starts on a fresh, empty one unnoticed.
  • A bind mount works too, if the directory is owned by the image's user: sudo chown 10001:10001 state && sudo chmod 700 state. It must be on a local file system: the store's write-ahead log does not work over a network file system, and a Docker Desktop bind mount passes through a file share of its VM. Use a named volume there.
  • Stop the container with a timeout above printer.write_timeout plus 10 seconds, --stop-timeout 40 at the defaults, so a receipt being written to the printer can finish. Docker's default, 10 seconds, can kill that write, and the job then reads uncertain.
  • Two containers must never share the directory: the second does not start.

A job store that will not open

If jobs.db is damaged, or was written by a newer version, the container stops at start with an error naming the file (docker logs). It does not start with an empty store, which would forget the jobs still waiting and which receipts may have printed. To set the store aside, with the container stopped, move jobs.db and jobs.db-wal out of the volume together, then start it again:

docker stop <container>
docker run --rm -v uberbringer-state:/state -v "$PWD:/out" alpine \
  sh -c 'mkdir -p /out/broken-store && mv /state/jobs.db* /out/broken-store/'
docker start <container>

The jobs in the old store are forgotten, so check the last receipts on paper against what was sent. The moved files hold what those receipts printed: delete them once you no longer need them.

ntfy subscriptions

Subscriptions are set in config.toml only, so a container with one needs the file. The image runs as user and group 10001, so give a token file to that ID, mode 600, and mount it read-only next to the config:

sudo chown 10001:10001 ntfy.token && sudo chmod 600 ntfy.token
docker run ... -v "$PWD/ntfy.token:/etc/uberbringer/ntfy.token:ro" uberbringer