Skip to content

Print agent

The print agent is a small program on a computer next to the printers of a range, typically a Raspberry Pi with CUPS. It only makes outgoing HTTPS requests to Targetlog: it reports the CUPS printers and their options, waits for jobs (long polling) and prints them with lp. No port needs to be opened at the range.

Installation

  1. In the app, Ranges → Printing → Add print agent; copy the token (shown only once).
  2. Download the binary for the computer (targetlog-print-agent-linux-amd64 or -arm64, artifacts of the CI job print-agent, or make agent) and install it:

    install targetlog-print-agent-linux-arm64 /usr/local/bin/targetlog-print-agent
    printf 'TARGETLOG_URL=https://app.targetlog.ch\nTARGETLOG_AGENT_TOKEN=<token>\n' > /etc/targetlog-print-agent.env
    chmod 600 /etc/targetlog-print-agent.env
    install -m 644 print-agent.service /etc/systemd/system/targetlog-print-agent.service
    systemctl enable --now targetlog-print-agent
    
  3. Back in the app, the agent shows as online with its printers. Assign a printer and its options to each document (see Printing).

Configuration

Variable Default Description
TARGETLOG_URL required base URL of Targetlog
TARGETLOG_AGENT_TOKEN required token from Add print agent
TARGETLOG_LP lp print command
TARGETLOG_LPSTAT lpstat used to list printers
TARGETLOG_LPOPTIONS lpoptions used to read printer options (trays, paper sizes, media types)

The systemd unit runs the agent as a dynamic user and restarts it on failure. journalctl -u targetlog-print-agent shows its log.

Behaviour

  • Documents are printed with lp -d <printer> -t <title> -o <options>; the options come from the printing setup of the range.
  • A job that is not confirmed within two minutes goes back to the queue; after three attempts it fails. Jobs are deleted after a week.
  • The app treats an agent as online when it was seen within the last minute. Without an online agent, documents open as PDF in the browser.
  • Revoking the agent in the app invalidates its token immediately.