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>
279 lines
17 KiB
Markdown
279 lines
17 KiB
Markdown
# Configuration
|
||
|
||
The daemon reads its settings from a TOML file and from environment
|
||
variables. [configs/config.example.toml](../configs/config.example.toml)
|
||
shows every setting with its default: copy it to `config.toml` to start.
|
||
`install.sh` and the Docker image keep the config in
|
||
`/etc/uberbringer/config.toml`.
|
||
|
||
## Contents
|
||
|
||
- [Loading](#loading)
|
||
- [Environment variables](#environment-variables)
|
||
- [Settings](#settings): [webserver](#webserver), [api](#api),
|
||
[printer](#printer), [format](#format), [ntfy](#ntfy),
|
||
[ntfy subscriptions](#ntfy-subscriptions), [queue](#queue),
|
||
[state](#state), [images](#images), [sentry](#sentry), [log](#log)
|
||
- [Logs](#logs)
|
||
|
||
## Loading
|
||
|
||
- Only `api.secret` and `printer.address` are required. Every other setting
|
||
has a default.
|
||
- Unknown keys are errors, so a typo can't silently fall back to a default,
|
||
and so are two keys that differ only in case.
|
||
- A duration is a string such as `"5s"` or `"1m30s"`; a bare number is
|
||
refused.
|
||
- `--config` names the file, and defaults to `config.toml` or to
|
||
`UBERBRINGER_CONFIG` when that is set. `--config ""`, or an empty
|
||
`UBERBRINGER_CONFIG`, reads no file, so the settings come from the
|
||
environment and the defaults alone.
|
||
- [`uberbringer config get <key>`](cli.md#config-get) prints a setting as
|
||
the daemon would use it.
|
||
|
||
## Environment variables
|
||
|
||
Every key can also be set by an environment variable named
|
||
`UBERBRINGER_<SECTION>_<KEY>`, such as `UBERBRINGER_PRINTER_ADDRESS` for
|
||
`printer.address`, and a variable wins over the file. The exception is the
|
||
[ntfy subscriptions](#ntfy-subscriptions), a list of tables, which only the
|
||
file sets.
|
||
|
||
- Values are written without quotes: decimal digits for a number, `true` or
|
||
`false` for a flag, `5s` for a duration. Lists take comma-separated values,
|
||
e.g. `UBERBRINGER_WEBSERVER_TRUSTED_PROXIES=127.0.0.1,::1`; an empty item,
|
||
from a doubled or trailing comma, is an error. In the file, a number, flag
|
||
or list may also be written as such a string.
|
||
- A table of your own entries, `ntfy.markers`, takes `name=value` entries
|
||
separated by commas, e.g. `UBERBRINGER_NTFY_MARKERS=backup=[B],nas01=`; a
|
||
value cannot hold a comma.
|
||
- An empty variable counts as unset, and one that holds only spaces is an
|
||
error. Variables that name no key are ignored, but when the configuration
|
||
fails to load, the error names them, since they are likely misspelt.
|
||
|
||
## Settings
|
||
|
||
### webserver
|
||
|
||
| Key | Default | Meaning |
|
||
|-----|---------|---------|
|
||
| `bind_ip` | `"127.0.0.1"` | The IP address the HTTP server listens on; `"0.0.0.0"` in [Docker](docker.md) |
|
||
| `port` | `8080` | The port it listens on, 1–65535 |
|
||
| `rate_limit`, `rate_window` | `60`, `"1m"` | Each client may make this many `/api` requests per window; more get `429` `rate_limited` |
|
||
| `trusted_proxies` | `["127.0.0.1", "::1"]` | IP addresses or CIDR ranges of reverse proxies. A request from one of them is counted, for the rate limit, against the client address in `proxy_header` |
|
||
| `proxy_header` | `"X-Real-IP"` | The header the proxy sets to the client's address. `install.sh` sets Caddy up to send it |
|
||
| `body_limit` | `4194304` | The largest request body, in bytes (4 MiB); a larger one gets `413` `body_too_large`. Raise it for large base64 images, and raise the proxy's limit with it |
|
||
| `read_timeout`, `write_timeout`, `idle_timeout` | `"15s"`, `"15s"`, `"60s"` | The HTTP server's timeouts |
|
||
|
||
`install.sh` copies `bind_ip`, `port` and `body_limit` into Caddy's config,
|
||
so on a host it set up, re-run it after changing them
|
||
([install.md](install.md#upgrading-and-changing-the-config)).
|
||
|
||
### api
|
||
|
||
| Key | Default | Meaning |
|
||
|-----|---------|---------|
|
||
| `secret` | none | Required. The key that signs bearer tokens (HS256), at least 32 bytes. `uberbringer secret` makes one; see [security.md](security.md#the-api-secret) |
|
||
|
||
### printer
|
||
|
||
| Key | Default | Meaning |
|
||
|-----|---------|---------|
|
||
| `address` | none | Required. The printer's IP address or host name |
|
||
| `port` | `9100` | The printer's TCP port, 1–65535 |
|
||
| `model` | `"tm-t88"` | The printer's profile, which sets the print width and characters per line; see below |
|
||
| `codepage` | `"cp437"` | The code page text is transcoded to: `cp437`, `cp850`, `cp858` (has €) or `cp1252` |
|
||
| `paper_width` | the model's | The printable width in dots; overrides the model |
|
||
| `columns` | from the width | Font A characters per line, for word wrap; overrides the model |
|
||
| `box_line_spacing` | `0` | The line spacing, in motion units (ESC 3, 0–255), used while a box prints. Lines of box drawing leave small gaps in the vertical borders at the printer's default spacing; a value checked on paper closes them. `0` keeps the default |
|
||
| `cut_feed` | `3` | Blank lines, 0–255, fed before every cut, the one after each copy and `cut` elements alike, so that the last printed line does not sit right at the cut. They show in previews and count toward `format.max_lines` |
|
||
| `dial_timeout`, `write_timeout` | `"5s"`, `"30s"` | How long connecting to the printer, and sending it a job, may take |
|
||
| `retries` | `3` | How many times a failed send is retried before the job fails |
|
||
| `retry_delay` | `"1s"` | The wait before the first retry; it doubles after each |
|
||
|
||
The models:
|
||
|
||
| Model | Printers | Width | Font A / B columns |
|
||
|-------|----------|-------|--------------------|
|
||
| `tm-t88` (default) | TM-T88IV, V, VI, VII | 512 dots (180 dpi) | 42 / 56 |
|
||
| `tm-m50` | TM-m50, TM-m50II | 512 dots (180 dpi) | 42 / 56 |
|
||
| `tm-t20` | TM-T20, II, III | 576 dots (203 dpi) | 48 / 64 |
|
||
| `generic-80mm` | other 80 mm, 203 dpi | 576 dots | 48 / 64 |
|
||
| `generic-58mm` | 58 mm paper, 203 dpi | 384 dots | 32 / 42 |
|
||
|
||
For 58 mm paper on a 180-dpi printer (TM-T88VII, TM-m50II), use a `tm-t88`
|
||
or `tm-m50` model with `paper_width = 360` (30 Font A columns).
|
||
|
||
If words break at the right edge (for example `seve` on one line and `ral`
|
||
on the next), the model is wider than the printer.
|
||
|
||
### format
|
||
|
||
| Key | Default | Meaning |
|
||
|-----|---------|---------|
|
||
| `max_lines` | `2000` | A job that would print more lines, all copies counted, fails instead of printing, and `/api/v1/preview` answers it with `422`. It is a backstop against runaway text |
|
||
| `timezone` | `"Local"` | The zone of the times [modules](api.md#modules) print, such as a note's stamp: an IANA name such as `Europe/London` or `UTC`, or `Local` for the host's zone. The binary carries the zone database, so names load on hosts and containers without one |
|
||
| `time_layout` | `"02 Jan 15:04"` | How those times print, in Go's notation, in which `02 Jan 2006 15:04:05` stands for the parts of a date, e.g. `2006-01-02 15:04`. A layout that shows no part of a date is an error |
|
||
|
||
### ntfy
|
||
|
||
These settings shape the [notification cards](api.md#notification-cards)
|
||
of the `notify` and `ntfy` modules and of the [ntfy subscriptions](ntfy.md),
|
||
and their [digests](api.md#digests).
|
||
|
||
`[ntfy.format]`:
|
||
|
||
| Key | Default | Meaning |
|
||
|-----|---------|---------|
|
||
| `style` | `"auto"` | `auto` picks the form from the priority; `box` prints priorities 1 and 2 in a box too; `compact` prints every priority without a box |
|
||
| `max_lines` | `40` | 1–400 lines of the message, as written, before `... N more lines` |
|
||
| `qr` | `"all"` | Which links print as QR codes: `all`, `first` (the rest as text) or `none` |
|
||
| `images` | `true` | `false` names attached images on a `File` row instead of printing them |
|
||
| `markdown` | `true` | `false` prints markdown messages as written |
|
||
| `updates` | `"print"` | What a subscription does with a message that replaces one it printed: `print` marks its title `(updated)`, `skip` leaves it out |
|
||
|
||
`[ntfy.markers]` adds or changes the [markers](api.md#markers) printed for
|
||
tags, at most 16 characters each, and `""` hides a tag: `backup = "[B]"`,
|
||
`nas01 = ""`.
|
||
|
||
### ntfy subscriptions
|
||
|
||
Each `[[ntfy.subscriptions]]` table is one connection to one ntfy server,
|
||
for one or more topics. They are set in the file only, and need
|
||
[`state.dir`](#state). [ntfy.md](ntfy.md) shows an example and how a
|
||
subscription behaves.
|
||
|
||
| Key | Default | Meaning |
|
||
|-----|---------|---------|
|
||
| `name` | required | 1–32 lowercase letters, digits, `-` and `_`. It names the subscription in `/healthz`, in logs, in its state file and in its jobs' source, `ntfy:<name>`; each must be unique |
|
||
| `server` | required | The server's base URL. It must be `https` unless `allow_insecure = true`. A redirect is never followed: the connection fails, and `last_error` says to set the address it points to |
|
||
| `allow_insecure` | `false` | `true` allows a plain `http` server, whose credentials and messages cross the network unencrypted |
|
||
| `topics` | required | 1–150 topic names, each 1–64 letters, digits, `-` and `_` |
|
||
| `token`, `token_file`, or `user` with `password_file` | none | The credentials, at most one kind. A file holds the secret alone; spaces and line breaks around it are ignored, and a file the group or others can read is accepted with a warning. Without any, the subscription reads as anyone may |
|
||
| `min_priority` | `1` | The lowest priority that prints; the server filters by it |
|
||
| `max_backlog` | `"1h"` | How far back messages missed during a restart or an outage still print, at most `12h`, the time ntfy keeps them by default |
|
||
| `rate_limit`, `rate_window` | `5`, `"10m"` | The paper budget: at most this many receipts (1–1000) in any window. Messages over it are held, and print together on one [digest](api.md#digests) once the budget has room |
|
||
| `bypass_priority` | `5` | Outside quiet hours, messages of this priority and above print at once, outside the budget. During quiet hours, `quiet.min_priority` decides first |
|
||
| `keepalive` | `"45s"` | The server's keepalive interval, 5s–1h. A connection silent for twice this plus 15 s is opened again |
|
||
|
||
Quiet hours are off unless the subscription has a
|
||
`[ntfy.subscriptions.quiet]` table, which goes right after its
|
||
`[[ntfy.subscriptions]]` table:
|
||
|
||
| Key | Default | Meaning |
|
||
|-----|---------|---------|
|
||
| `start`, `end` | `"22:00"`, `"07:00"` | The window, as HH:MM. An end before the start is on the next day; the times hold on the nights the clocks change |
|
||
| `days` | every day | The days a window starts on: `mon`, `tue`, `wed`, `thu`, `fri`, `sat`, `sun`. With `["fri"]`, Friday's window runs into Saturday morning |
|
||
| `timezone` | `format.timezone` | The zone of `start` and `end` |
|
||
| `min_priority` | `5` | The lowest priority that prints during the window |
|
||
| `action` | `"digest"` | `digest` holds the other messages and prints them on one `Overnight` digest when the window ends; `drop` leaves them out |
|
||
|
||
### queue
|
||
|
||
| Key | Default | Meaning |
|
||
|-----|---------|---------|
|
||
| `size` | `100` | Jobs that may wait to print; more get `503` `queue_full` |
|
||
| `history` | `1000` | Finished jobs whose status is kept; an older job's ID answers `404` `job_not_found` |
|
||
| `content_bytes` | `67108864` | The bytes of finished jobs' content kept, newest first, each job as its JSON: 64 MiB, at most 1 GiB (`1073741824`). Jobs not yet finished keep theirs whatever the total, and so do `uncertain` jobs while their status is kept. The content is kept in the [job store](#state) with `state.dir`, and in memory without it |
|
||
|
||
### state
|
||
|
||
| Key | Default | Meaning |
|
||
|-----|---------|---------|
|
||
| `dir` | none | The directory of the job store, `jobs.db`, and of the [ntfy subscriptions](#ntfy-subscriptions)' state, one `ntfy-<name>.json` file each, all readable by the daemon's user only. Empty keeps jobs in memory. Required with a subscription, and never only spaces. When it is set, the daemon creates it, readable by its user only, if it is missing, and does not start if it cannot write there. `install.sh` and the Docker image set it to `/var/lib/uberbringer` |
|
||
|
||
With `state.dir`, the daemon keeps every job in the job store, `jobs.db`, a
|
||
SQLite database, with its log `jobs.db-wal` beside it:
|
||
|
||
- Jobs still waiting when the daemon stops or crashes print after the next
|
||
start, in order, however old, and every kept status answers after a
|
||
restart. A job that was being sent to the printer when the daemon stopped
|
||
reads `uncertain` and is never sent again
|
||
([api.md](api.md#job-status)). Without `state.dir`, waiting jobs are
|
||
marked failed when the daemon stops, and forgotten after a crash.
|
||
- A job accepted from the HTTP routes is written to disk within about 30
|
||
seconds, or sooner with the next job sent to the printer, so a power cut
|
||
just after its `202` can lose it, but never prints it twice. A job from
|
||
an ntfy subscription is on disk before it is queued.
|
||
- One daemon uses a directory at a time: a second one on it does not
|
||
start. No other program, the `sqlite3` command included, can read the
|
||
database while the daemon runs.
|
||
- The store holds what the receipts print, each job as its JSON, never a
|
||
token. Its files are readable by the daemon's user only, and the content
|
||
of a job that is gone can linger in the file's free pages until they are
|
||
reused. `queue.content_bytes` bounds how much content is kept.
|
||
- A store that cannot be opened, such as a damaged one, stops the daemon
|
||
with an error naming the file. [install.md](install.md#a-job-store-that-will-not-open)
|
||
and [docker.md](docker.md#a-job-store-that-will-not-open) say how to set
|
||
it aside.
|
||
- `jobs.db` and `jobs.db-wal` belong together: never delete the log, or
|
||
copy the database without it.
|
||
- Going back to 0.2.0: it refuses every key added since as unknown, such
|
||
as `[state]`, `queue.content_bytes`, `printer.cut_feed` and the `ntfy`
|
||
tables, so remove them first, and it never reads `jobs.db`, so the jobs
|
||
waiting in it do not print.
|
||
|
||
### images
|
||
|
||
| Key | Default | Meaning |
|
||
|-----|---------|---------|
|
||
| `timeout` | `"10s"` | How long fetching an image may take |
|
||
| `max_bytes` | `10485760` | The largest image download, in bytes (10 MiB) |
|
||
| `max_pixels` | `25000000` | The largest decoded image, in pixels, against decompression bombs |
|
||
| `max_height` | `4000` | The tallest printed image, in dots after scaling, about 50 cm |
|
||
| `allow_private_networks` | `false` | `true` lets image URLs reach loopback, private and link-local addresses |
|
||
| `allowed_hosts` | `[]` | When set, the only hosts images may come from; those hosts may be on your LAN |
|
||
|
||
An image that breaks a limit fails its job, unless the image is `optional`
|
||
([image](api.md#image)).
|
||
|
||
### sentry
|
||
|
||
| Key | Default | Meaning |
|
||
|-----|---------|---------|
|
||
| `dsn` | none | Where errors are reported. When neither the file nor `UBERBRINGER_SENTRY_DSN` sets it, it falls back to the `SENTRY_DSN` environment variable, then to a DSN built into release binaries |
|
||
| `environment` | `"production"` | The environment events are reported under |
|
||
| `debug` | `false` | `true` has the Sentry client log what it does |
|
||
|
||
Request bodies and the `Authorization` header are never sent to Sentry.
|
||
|
||
### log
|
||
|
||
| Key | Default | Meaning |
|
||
|-----|---------|---------|
|
||
| `level` | `"info"` | `debug`, `info`, `warn` or `error` |
|
||
| `format` | `"text"` | `text` or `json` |
|
||
|
||
## Logs
|
||
|
||
- Each request is logged once, as `request`: at INFO, or at WARN when the
|
||
status is 5xx. Only the path is logged, never the query string, the body
|
||
or the token.
|
||
- The worker logs each job with its `job_id`, its `source` (`print`,
|
||
`module:<name>` or `ntfy:<name>`) and its `ref`, the ID of the request or
|
||
ntfy message that sent it, or a digest's own reference, never with what
|
||
it prints.
|
||
- With `state.dir`, a start that finds jobs in the store logs
|
||
`print queue restored` at INFO, with how many `jobs` it holds, how many
|
||
are `waiting` and how many are `uncertain`. Each job that was being sent
|
||
when the daemon stopped is logged at WARN once, by its `job_id`,
|
||
`printer`, `source` and `ref`: it may have printed and is not sent again,
|
||
so check the paper. A job that a stop catches before it reached the
|
||
printer is logged at INFO as `job left queued` and prints after the
|
||
start.
|
||
- Each [ntfy subscription](ntfy.md) logs with its `subscription` name,
|
||
never with what a message says or its topic. It logs at WARN when its
|
||
connection is lost, when its credentials are refused and while the queue
|
||
is full, and at DEBUG what happens to each message.
|
||
- An unexpected failure is logged at ERROR and reported to Sentry once: a
|
||
request that fails or panics, a job that fails after its retries
|
||
(`job failed`), a module that builds an invalid receipt, a notification
|
||
card or digest that prints its plain fallback, an ntfy state file that
|
||
cannot be written, and a job store that fails (`print queue stopped`),
|
||
which stops the daemon. A request whose job it could not store answers
|
||
`500` `internal_error`; the failure is logged and reported with the
|
||
stop, not again for the request.
|
||
- Refusals are never logged at ERROR and never go to Sentry. They are the
|
||
4xx answers other than `module_failed`, the `queue_full` and
|
||
`shutting_down` 503s, and 503s from `/healthz`.
|