Packages
Connect knows no clock vendor. Each clock protocol lives in a protocol package. A protocol package is Lua that does three things:
- It reads the messages a clock sends.
- It builds the commands the clock takes.
- It maps the standard actions to those commands.
You install the official packages. You can also write your own for a clock nobody supports yet. You can replace packages on a running install. A message being handled at the switch finishes on the revision it started with.
This page covers running packages. To write one, see Writing packages. For the development loop against a real clock, see Developing packages.
Protocol packages belong to the install. A tenant’s decisions at the clock are policy packages (kind = "policy" in package.toml). Examples of such decisions are routing a punch, a clock joining, and a person enrolled at a clock.
Policy packages are built and tested with the same hourctl pkg commands. They are pushed to a tenant, or published once as shared packages that tenants adopt.
POST /api/packages refuses a policy package. A tenant’s package route refuses a protocol package.
Official packages
Section titled “Official packages”| Package | Transport | For |
|---|---|---|
[email protected] | MQTT | An example protocol that no real device speaks. Use it as the model for an MQTT package. |
[email protected] | HTTP | ZKTeco PUSH (ADMS) clocks reporting pushver 3.x |
[email protected] | HTTP | ZKTeco PUSH clocks reporting pushver 2.4.x |
[email protected] | HTTP | ZKTeco PUSH clocks reporting pushver 2.0.x |
The ZKTeco PUSH page covers the ZK packages. hourctl pkg show <name> lists what any package offers. That is its commands, standard actions, own actions, settings and endpoint options.
BrightLink and lost commands
Section titled “BrightLink and lost commands”A command pushed to a BrightLink device over MQTT stays in the device’s hand until something says it is missed. The time it takes decides nothing. The package says so, in M.missed, and BrightLink says three things.
- The device takes the commands of its topic one at a time. It acks each in the order they came. An ack for a command says the writes before it that have no ack were missed (
M.missednames them from the hand and the ids the message acks). - The first heartbeat the device sends on a new broker connection carries
"birth": true. That means the device has (re)subscribed.- A broker that restarted without persistence loses what was pushed in between. So does a command published while the device was not subscribed. The broker’s QoS 1 cannot say so to the gateway.
- The birth heartbeat does say so. What is in the device’s hand without an ack is missed (
[commands] missed_on = ["heartbeat"],M.missed). - The exception is a reboot, which the device answers as it comes back.
- A missed write is pushed once more, with the same id (
resend = "writes"). A write is a user added or deleted, a message, or settings. It leaves the device as setting it once would.- A write with a sensitive parameter is kept redacted and is never pushed again. An added user with a keypad PIN is an example.
- A command lost again, or one that is not a write, is
unanswered(command.unanswered, and its action fails). Examples of commands that are not writes are the time, the keys and clearing the log. - An ack that comes later still completes it.
- The ack of one command only concludes lost the writes before it. The others stay in hand until a birth heartbeat or an app’s give-up.
A device whose firmware sends no birth heartbeat keeps what it was pushed in its hand. It keeps it until an ack for a later command arrives, or an app gives up on it (hourctl action cancel --give-up).
The Hour Advantage distribution includes a bundle of each, ready to push. The container image holds them in /usr/share/houradvantage/packages.
Their sources are in the public example packages repository, hour-advantage-examples. It has zk/, brightlink/, and _types/ with editor types. The same repository holds the Connect policy recipes (policy/) and Time and Attendance’s policy cookbook (attendance/).
Build, push, activate
Section titled “Build, push, activate”Connect reads no package files from disk. Packages are kept in the database as bundles. Every instance runs the same active revision of each.
hourctl pkg build packages -o bundles # one <name>-<version>.tar.gz per packagehourctl pkg activate zk-push@3 # back to revision 3| Step | What it does |
|---|---|
hourctl pkg build <dir> [-o PATH] | Builds a package folder, or every package in a packages folder, into <name>-<version>.tar.gz. A bundle holds a manifest (name, version, host API, a SHA-256 content hash and the file list), package.toml, main.lua, every module the package requires, and its scenarios. The Lua is compiled, every declaration checked and the scenarios run. A package that fails any of it is not built. The same input makes the same bytes. Needs no gateway. |
hourctl pkg push <bundle>... [--activate] | Sends each bundle to POST /api/packages (at most 16 MiB and 2048 files). The gateway checks it all again and keeps it as a revision. A revision is numbered per package name from 1 and never changed. Pushing the same content again returns the revision it already is. --activate activates each one at once. Audited. |
hourctl pkg activate <name>@<revision> | Makes the revision the active one of its line. A line is a name and a major.minor version, such as [email protected]. If any endpoint would then not find or fit its package, it answers 400 and nothing changes. Otherwise every instance swaps the revision in while it keeps serving. A message under way finishes on the revision it started with. hourctl prints [email protected]: revision 7 runs on 3/3 instances. Audited. |
Endpoints name a package in one of four ways: by name (zk-push), by line ([email protected]), by major version (zk-push@3) or by exact version. An endpoint runs the active revision of the newest line that matches. A revision is never pinned per endpoint.
Bundles are not signed. Whoever holds the admin login can push one, so guard it as you would a deploy key.
Packages run sandboxed. They have no file, network or process access, and every call has a time and memory limit. But they are code you trust. Push only packages you would run.
Upgrade. Build (or take the image’s bundles), push, activate. Pushing and activating are idempotent. So a deploy step can run them on every deploy. The Compose packages service and the Kubernetes setup Job do.
Roll back. hourctl pkg show <name> lists the revisions. Activate the one before. Every revision pushed is kept.
Host API versions
Section titled “Host API versions”A package declares the host API it is written for (host_api in its package.toml). This version of Hour Advantage runs host APIs 1 and 2.
Write new packages for 2. It has the shared library built in. A host API 1 package carries its own copy of the library.
A version that does not run a bundle’s host API refuses it at build, push and load. It says what to do:
package [email protected] is written for host API 3; this build of Hour Advantage runs host API 1-2: upgrade Hour Advantage to run itDuring a rolling upgrade, instances of two versions may run side by side. An instance that cannot run an activated revision does three things. It keeps the revision it had for that line. It logs this instance cannot run the active package revision. It stays ready.
hourctl pkg activate and hourctl pkg push --activate then exit non-zero, naming the instance and the reason. The activation stands. The instance takes the revision once it runs a version that can.
Activate a revision for a new host API once every instance runs a version that has it.
An instance that starts and cannot run a line’s active revision at all leaves that line out. It does not serve an endpoint whose package it does not have. It logs endpoint not served on this instance. hourctl endpoints on that instance says why. So does unavailable on the endpoint in the API. The instance still starts, as does one on a fresh database with no packages.
What hourctl pkg show lists
Section titled “What hourctl pkg show lists”- Every revision: number, version, hash, host API, when and by whom it was pushed, and which is active.
- Per line: the active revision and when it was activated.
- Per instance: the revision it runs and, when it refused the active one, why (
REFUSED BECAUSE). - What the package offers: standard actions, its own actions, and its commands with their typed parameters and the sync domains each writes. Also its settings and its endpoint options (
--jsonadds the routes).
hourctl pkg list is the short form. It lists every line, its active revision, how many revisions are kept, and what the instance you asked runs.
What a package declares
Section titled “What a package declares”The package reference has every field. In short:
- Routes: every message kind a device sends. A message no route takes gets a 404 and is logged.
- Typed parameters for every command and action, checked against every request. A parameter that is unknown, missing or out of range is answered 422 with what is wrong with each field. Nothing is queued.
- What it writes: the sync domains each command and action changes. A sync group refuses (409) a command sent straight to a member when it writes a domain the group keeps (sync).
- Settings: each device setting the package can set, with a neutral name, type and range. Settings are set only with the standard action
set_settings, by those names. - Actions: the standard actions it offers, and its own actions for what the standard vocabulary has no word for.
- Endpoint options it reads, beside the gateway’s own (
biometrics,drop_events; see reference). - How the device answers (
[commands]). This says three things. Whether its answers come in the order it was handed commands. Which lost commands are handed out once more. Which of its requests say it restarted. A package that says nothing gets no conclusion drawn from how long a device takes. A command stays in its hand until it answers or you give up on it. - Requirements: the vars and secrets it cannot run without. A revision is not activated in a cluster that lacks one. A value a package in use requires cannot be deleted (environments).
hourctl device actions <endpoint> <device> and hourctl device options <endpoint> <device> show what one device takes, narrowed by what it reported.
Scenarios
Section titled “Scenarios”hourctl pkg test runs the scenarios of every package in a folder. It reports route, command and action coverage. hourctl pkg render prints the payload a command builds. Neither needs a gateway.
POST /api/scenarios/run runs the scenarios of the packages a running gateway uses, one run at a time (scenario tests).