Files
uberbringer/docs/configuration.md
T
57_WolveandClaude Opus 5.5 4eb620dde0 Check state.dir at start, with or without subscriptions
Breaking: the Docker image sets state.dir, so a container that cannot
write /var/lib/uberbringer, one started --read-only without a volume
there or with a bind mount owned by root, no longer starts, ntfy
subscriptions or not: mount a named volume or a directory owned by
10001:10001.

The daemon created state.dir and checked that it could write there only
when an ntfy subscription was configured, since only subscriptions kept
files in it. The job store will keep its database there too, so the
check now runs once at start whenever state.dir is set: the directory
is created 0700 if it is missing, and one that cannot be made or
written stops the start with an error naming state.dir, before any
subscription is made. A state.dir of only spaces is refused whether or
not a subscription is configured, rather than made as a directory of
that name. Without state.dir nothing changes.

Part of stage 1d of docs/plans/job-store.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-01 16:39:48 -06:00

240 lines
14 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 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 memory |
### state
| Key | Default | Meaning |
|-----|---------|---------|
| `dir` | none | The directory the [ntfy subscriptions](#ntfy-subscriptions) keep their state in, one `ntfy-<name>.json` file each, readable by the daemon's user only. 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` |
### 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.
- 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`.