Files
uberbringer/packaging/uberbringer.service
T
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

69 lines
2.7 KiB
Desktop File

[Unit]
Description=Uberbringer receipt printer server
Documentation=https://git.anomalous.dev/57_Wolve/uberbringer
Wants=network-online.target
After=network.target network-online.target
# Start-rate limits are [Unit] settings (systemd v230+); systemd ignores
# StartLimitIntervalSec= in [Service].
StartLimitIntervalSec=60
StartLimitBurst=3
# Change settings with `systemctl edit uberbringer` rather than editing this
# file: drop-ins in /etc/systemd/system/uberbringer.service.d/ survive upgrades.
[Service]
Type=simple
User=uberbringer
Group=uberbringer
WorkingDirectory=/etc/uberbringer
ExecStart=/usr/local/bin/uberbringer --config /etc/uberbringer/config.toml
Restart=on-failure
RestartSec=5
LimitNOFILE=4096
# TimeoutStopSec= stays at systemd's default, 90 s. A stop lets a receipt
# already being written to the printer finish, which takes up to
# printer.write_timeout (30 s) and two commits; keep any lower timeout above
# write_timeout plus 10 s, or the stop kills the write and leaves its job
# uncertain.
# ── Privileges ────────────────────────────────────────────────────────────────
# The daemon binds an unprivileged port, dials the printer over TCP and fetches
# images and reports errors to Sentry over HTTPS. It needs no capabilities.
CapabilityBoundingSet=
AmbientCapabilities=
NoNewPrivileges=true
# ── Sandboxing ────────────────────────────────────────────────────────────────
# The daemon reads its config and the system CA bundle, writes only its job
# store and the state of its ntfy subscriptions, and opens no devices. The
# file system is read-only to it, apart from /var/lib/uberbringer, which
# systemd creates for the service user (state.dir). The store holds what the
# receipts print, so every file the daemon creates there is its user's alone.
StateDirectory=uberbringer
StateDirectoryMode=0700
UMask=0077
ProtectSystem=strict
ProtectHome=true
PrivateTmp=true
PrivateDevices=true
ProtectKernelTunables=true
ProtectKernelModules=true
ProtectKernelLogs=true
ProtectControlGroups=true
ProtectClock=true
ProtectHostname=true
LockPersonality=true
MemoryDenyWriteExecute=true
RestrictSUIDSGID=true
RestrictRealtime=true
RestrictNamespaces=true
SystemCallArchitectures=native
SystemCallFilter=@system-service
SystemCallErrorNumber=EPERM
# IPv4 and IPv6 for the listener, the printer, DNS, image fetches and Sentry;
# AF_UNIX for local sockets such as the journal.
RestrictAddressFamilies=AF_INET AF_INET6 AF_UNIX
[Install]
WantedBy=multi-user.target