← Documentation index

SPPWORK

NAME
SYNOPSIS
DESCRIPTION
OPTIONS
CONFIGURATION
DIAGNOSTICS
SIGNALS
FILES
EXIT STATUS
EXAMPLES
SEE ALSO
AUTHOR
COPYRIGHT

NAME

sppwork - the worker of sapupra: records the scans, looks them up in the bibliographic sources and catalogues them

SYNOPSIS

sppwork [-c|--config FILE] [-s|--syslog] [-d|--debug |-q|--quiet]
sppwork -h
|--help
sppwork -V
|--version

DESCRIPTION

sppwork takes the inputs that the gateway (sppgate(8)) and the entry module publish on the MQTT broker, on the topics sapupra/v1/input/DEVICE. It is the only program that writes the database: it takes a lock file beside it (FILE.worker.lock), and a second worker started on the same database refuses to start.

For each input it first records it in the database, as it was received, and only then publishes the receipt on sapupra/v1/receipt/ID: an input that has a receipt is never lost. It then classifies the code (ISBN, product number, other), looks for the edition in the catalogue and, if it is not there, asks the sources in the order of the configuration, one request per second at most. It catalogues what it finds as an edition and an item, at the location that the scan device last set (or the place that the entry module gave the item), and publishes the verdict on sapupra/v1/verdict/ID, which the gateway turns into the answer to the scan device.

An input of kind remove takes a copy out of the catalogue, with a reason, and one of kind restore puts it back; nothing is deleted, and the label of a removed copy is answered "unknown". An order of kind correct replaces the description of the edition of an item (all its copies); the record received from a source is kept, and the ISBN is changed only for a description entered by hand. An order of kind place makes, renames, merges or deletes a place.

A scan of an edition that the catalogue holds needs no request; what it makes depends on [worker] copies: another copy, a scan held for the entry module to confirm (the default), or nothing. The same code read again by the same scan device within repeat_window seconds is taken for the same scan read again, not for another copy; a code read again while its lookup is under way, by any device, waits for it and is then handled as above; a code that no source knew is set aside once, and the later scans of it are told that it waits already.

A source that does not answer is not an answer: the input is kept as "unavailable" and tried again after 1 minute, 10 minutes, 1 hour, then every day, for 7 days; then it is set aside as not found. A scan taken while the worker was stopped waits for it at the broker (persistent session) and is handled on its return; an input recorded and not settled when the worker stopped is taken up again at its start.

The worker publishes, retained, the state online on sapupra/v1/status/worker, and offline when it stops or when the broker loses it.

It runs in the foreground, and is put in the background by the service manager: systemd on Debian (the unit sppwork.service), daemon(8) in an rc script on FreeBSD (the script sppwork).

OPTIONS

-c, --config FILE

The configuration file; by default /usr/local/etc/sapupra.ini (the sysconfdir of the installation).

-s, --syslog

Log to syslog, facility daemon, instead of standard error.

-d, --debug

Log the debugging messages too: each request to a source. On standard error each line then begins with the time, as HH:MM:SS.mmm.

-q, --quiet

Log only the warnings and the errors, not each scan.

-h, --help

Print the usage and exit.

-V, --version

Print the version and exit.

CONFIGURATION

The file is the one of the other programs, in the INI form; a value is taken as it is written (see sppgate(8)).
[broker] host
, port

The broker, as for the gateway.

[worker] user, password

The worker’s account at the broker. The account’s name is also the client identifier, which the persistent session is kept under: do not give two programs the same account.

[worker] contact

Required. An address at which the operators of the sources can reach you; it is sent with every request (User-Agent), as Open Library asks.

[worker] repeat_window

Seconds; 0 to 3600, by default 10.

[worker] copies

What to do with a scan, outside the repeat window, of an edition that the catalogue holds already: yes makes another copy (an item) at once; ask holds the scan in the to-do list of the entry module, as "another copy?", until it is confirmed there or dismissed; no adds nothing and tells the scan device that the item is catalogued already. By default ask.

[worker] log_level

One of quiet, normal and debug: the same as the options -q, nothing, and -d. By default normal. The option of the command line, if there is one, wins: a service can keep a quiet or a normal level in the file, and a run by hand ask for -d without touching it.

[database] file

The catalogue, a SQLite file. The directory must exist and belong to the worker’s account; the file is created if it does not exist. By default catalogue.db in the directory that configure chose (--with-databasedir): /var/lib/sapupra with the systemd units, which make it (StateDirectory), /var/db/sapupra with the rc scripts, otherwise sapupra under the localstatedir of the installation.

[sources] isbn.default

The sources to ask for an ISBN, in order, until one knows it; by default openlibrary, bnf. The sources of this version are openlibrary (ISBN), bnf (the Bibliothèque nationale de France: ISBN and the barcodes of documents) and musicbrainz (barcodes of CDs); and, if the program was built with YAZ, oszk (the Hungarian national library, by Z39.50: ISBN) and sbn (the Italian union catalogue, by Z39.50: ISBN) and loc (the Library of Congress, by Z39.50: ISBN). The German national library, dnb, (SRU: ISBN) is always there. A name that is not one of them is refused at the start. The BnF is asked for the 13 digits of an ISBN first and, if it has no record, for the 10 digits of the same book (an ISBN beginning with 978): it indexes the ISBN as it was printed.

[sources] isbn.978-2, isbn.979-10, ...

The sources for a registration group, named by the first digits of the ISBN-13; the longest prefix that fits an ISBN decides, else isbn.default. Built with YAZ, the worker asks for the Hungarian books (978-963, 978-615) oszk, openlibrary, bnf and for the Italian ones (978-88, 979-12) sbn, openlibrary, bnf; the German ones (978-3) dnb, openlibrary, bnf, and, with YAZ, the English ones (978-0, 978-1, 979-8) openlibrary, bnf, loc; a line of the file for the same prefix wins.

[sources] gtin, ismn, issn

The sources for the other codes. By default gtin is musicbrainz, bnf; the others have none, and such a code is set aside as "not an ISBN".

[sources] search

The sources asked for a search by author and title, by default openlibrary, bnf. Every source of the list is asked, and the books they know are offered together, up to ten, the same book once. If none has a book with all the words of the title, the worker asks again with the two longest words of the title (and the author as typed), and says so in the verdict. The Z39.50 sources can be named too (oszk searches by the words of the author and by the first words of the title; sbn has not been tried; dnb searches title and author); a source that does not answer is mentioned in the verdict only if no other has anything.

[sources] lccn

The sources asked for a card number of the Library of Congress (the search of the page /search with the field of the card number), by default loc; only that one can. A number is written as printed in the book (73-1830, 2001-012345, n78-890351) and is searched in its normal form (73001830). Without YAZ no source can be asked, and the verdict says so.

[sources] oszk.address, sbn.address, loc.address

Where the Z39.50 servers are, as host:port/database; by default tagetes2.oszk.hu:1616/B1

opac.sbn.it:2100/nopac and lx2.loc.gov:210/LCDB. A request is a connection, a search on the ISBN (the OSZK is asked the ISBN-10 first, it does not find the ISBN-13; SBN the ISBN-13 first) and the first five records; if the server has several records for one number (SBN has three editions of the same ISBN), the first is catalogued and all are kept as the sources of the item.

[sources] timeout

Seconds to wait for a source before taking it for silent; 1 to 300, by default 60 (Open Library took from 4 to 17 seconds to set up a connection in the trial of 0.14.0). The Z39.50 sources wait at most 60 seconds.

[sources] attempt

Seconds without any answer, not one byte, after which a request to a source is given up and made again on a new connection, until timeout has passed; 0 to 300, by default 8; 0 asks only once. A packet lost while a connection is set up is sent again by TCP after 1, 3, 7, 15 seconds, so that a new try is often quicker than the wait (the connections to Open Library in the trial of 0.16.0 took 1.2, 3.4 and 15.9 seconds, or never).

[sources] http2, keepalive

Yes or no (also true, false, on, off, 1, 0). Whether Qt may negotiate HTTP/2, by default no; whether the connection is kept after the answer, by default no (every request says Connection: close). The defaults avoid a warning of Qt; they are settings in case a source does not answer to them.

DIAGNOSTICS

A connection to the broker that fails is reported as for the gateway, naming [worker] user and password. A database that cannot be opened is reported with its reason: the directory must exist and belong to the worker’s account; a file that is not a catalogue of sapupra, or is of a later version, is refused and left as it is. A configuration that lacks a Qt SQLite driver, FTS5 or TLS is refused by configure at the build, and by the program at its start if the system changed.

A source that does not answer is reported with how long it was waited for ("Open Library does not answer: Operation timed out (after 60003 ms)"); with --debug, every request is logged with its address, its status, its duration and the HTTP version used.

The log of a scan shows the scan device, the code, the status and the text of the verdict; the statuses are received, resolved, repeated, located, found, not-found, not-isbn, ambiguous, unavailable and unrecognized.

SIGNALS

SIGTERM, SIGINT

Stop: the offline state is published, the connection to the broker is closed, the log of the database is moved into its file and the database is closed, and the program exits.

SIGHUP

Ignored: restart the service to read the configuration again.

FILES

/usr/local/etc/sapupra.ini

The configuration, owned by root, mode 0644: every account reads it.

/usr/local/etc/sapupra.secret.ini

The secrets (the broker’s password of the worker), owned by root, group sapupra, mode 0640: the services read it, and its values win over the configuration’s. Its name is that of the configuration file with .secret before the .ini.

/var/lib/sapupra/catalogue.db
/var/db/sapupra/catalogue.db

The catalogue on Debian and on FreeBSD, if the configuration says so (the sample does); with the files catalogue.db-wal and catalogue.db-shm beside it while a program has the database open: the log of what was recorded, which the worker moves into the file when it stops, and its index in shared memory (they stay, empty, if the entry module is stopped after the worker). The directory is owned by sapupra, mode 0755; the files are readable by all. Copy the catalogue with sppbackup(8) (it runs the command sqlite3 catalogue.db .backup copy.db and checks the copy), or copy the file alone, after the worker has been stopped.

EXIT STATUS

0

Stopped by a signal.

1

The configuration cannot be read or holds an invalid value, the database cannot be opened, or TLS is missing; the message says which and what to do.

2

A usage error.

EXAMPLES

Run it by hand, with the messages of each request, beside the gateway:

sppwork --debug --config ./sapupra.ini

Look at what it catalogued:

sqlite3 /var/lib/sapupra/catalogue.db select * from catalogue

SEE ALSO

sppbackup(8), sppgate(8), mosquitto(8), daemon(8), systemd.service(5), Design.org, section "The worker"; Manual.org, section "The worker".

AUTHOR

Péter Felecan, assisted by Claude Opus 5.5 (Anthropic).

COPYRIGHT

Copyright (C) 2026 Péter Felecan. License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.