Skip to content

hourd: the server

Run the server (Hour Advantage Connect, and Time and Attendance where enabled), check that it answers, and run the development gateway that serves the packages in a folder as they are on disk. hourd is the only program that accepts connections.

hourd run

Run the server: Hour Advantage Connect, and Hour Advantage Time and Attendance where enabled.

Listeners, endpoints, sinks, packages and everything else the gateway does are kept in its Postgres database and changed at run time through the admin API (hourctl). Every instance that shares the database runs the same setup. With HOURADVANTAGE_ATTEND=on, the instance also runs Time and Attendance, for every tenant of the install. The log goes to stdout: text at a terminal, JSON lines otherwise.

The admin login comes from HOURADVANTAGE_ADMIN_USERNAME and HOURADVANTAGE_ADMIN_PASSWORD_HASH (houradm hash-password makes the hash), and the key that seals secrets from HOURADVANTAGE_SECRET_KEY (houradm gen-secret-key makes it). Without the key, an instance refuses to start while the database keeps any secret (a broker password, a webhook signing secret, a device key, a tenant’s secret), unless HOURADVANTAGE_ALLOW_PLAIN_TEXT_SECRETS=true allows keeping them in plain text.

hourd run [OPTIONS]

Options:

  • --database-url <URL>: The Postgres database everything is kept in, shared by every gateway instance, e.g. postgres://houradvantage:[email protected]/houradvantage. Default: $HOURADVANTAGE_DATABASE_URL, or the contents of the file $HOURADVANTAGE_DATABASE_URL_FILE names.
  • --database-session-url <URL>: The database as the connections that keep a session (the lease and membership locks, LISTEN) reach it, when —database-url leads to a pooler that shares server connections between transactions such as PgBouncer in transaction mode: the database itself, not the pooler. Default: $HOURADVANTAGE_DATABASE_SESSION_URL, or the contents of the file $HOURADVANTAGE_DATABASE_SESSION_URL_FILE names; else the database URL serves for both. It may name another role than —database-url’s: a connection that keeps a session is taken away by the other’s, when its wait must end, so the role of —database-url must be the session role’s own, or a member of pg_signal_backend (else the wait ends only when its query is cancelled, which the server ignores between two statements).
  • --database-pooler-unchecked: Goes on when the checks of a pooler in front of the database cannot tell whether it keeps a session or prepared statements (it may be allowed one server connection only, or have none to give within its own wait): without this the start is refused, saying what to check. A pooler found not to keep them is refused either way. Default: $HOURADVANTAGE_DATABASE_POOLER_UNCHECKED. Environment: HOURADVANTAGE_DATABASE_POOLER_UNCHECKED.
  • --cache-url <URL>: The Valkey the instances of this install share a cache in, e.g. redis://valkey.example.com:6379 (redis-sentinel://, redis-cluster:// and rediss:// too). With it any number of instances may share the database. Without it the instance keeps its own cache and is the only instance: a second one, or one with a Valkey beside one without, refuses to start. Default: $HOURADVANTAGE_CACHE_URL, or the contents of the file $HOURADVANTAGE_CACHE_URL_FILE names.
  • --cache-install <ID>: The install’s id in the Valkey, the first part of every key, so that installs may share one Valkey. Default: $HOURADVANTAGE_CACHE_INSTALL, else “default”.
  • --cache-reconnect-first-ms <MS>: The pause before the first try to reach the Valkey again when its connection is lost, in milliseconds. Each later pause is twice the one before, up to the longest. Default: $HOURADVANTAGE_CACHE_RECONNECT_FIRST_MS, else 100.
  • --cache-reconnect-longest-ms <MS>: The longest pause between tries to reach the Valkey again, in milliseconds. Default: $HOURADVANTAGE_CACHE_RECONNECT_LONGEST_MS, else 30000.
  • --admin-listen <ADDR>: Where the admin API (and /metrics) listens, IP:PORT, e.g. 0.0.0.0:9090. Anywhere but loopback needs an admin login (HOURADVANTAGE_ADMIN_USERNAME and HOURADVANTAGE_ADMIN_PASSWORD_HASH). Default: 127.0.0.1:9090. Environment: HOURADVANTAGE_ADMIN_LISTEN.
  • --advertise-addr <ADDR>: Where the other instances reach this one’s admin API, for live views across every instance (hourctl wire, hourctl stream): host:port, a host (the admin port is added) or http(s)://host:port. Default: detected, as the admin listener’s address, or this host’s (POD_IP, or the address it reaches the database from). Environment: HOURADVANTAGE_ADVERTISE_ADDR.

Example:

Terminal window
hourd run --database-url postgres://houradvantage:[email protected]/houradvantage

hourd healthcheck

Check that the server on this machine answers, for a container health check.

Asks GET /livez on the admin listener (or /api/ready with —ready), on loopback when the listener is on every address, and waits at most 3 seconds. Exits 0 on a 2xx answer, 1 otherwise. Prints nothing on success.

hourd healthcheck [OPTIONS]

Options:

  • --ready: Ask whether it takes work (/api/ready) rather than whether it is alive (/livez).
  • --admin-listen <ADDR>: The admin listener’s address, IP:PORT, as run was given it. Default: 127.0.0.1:9090. Environment: HOURADVANTAGE_ADMIN_LISTEN.

Example:

Terminal window
hourd healthcheck --ready

hourd dev

Develop packages: the whole gateway, running the packages in a folder as they are on disk.

Runs the admin API, actions, sync groups, events and live views with the setup in ./dev.toml (and ./dev.local.toml laid over it), reloads a package when one of its files is saved, and keeps everything in memory unless —database-url names a database. Shows every exchange with a device as it happens. The admin API listens on HOURADVANTAGE_ADMIN_LISTEN, else 127.0.0.1:9090, so hourctl works against it. hourd dev init writes a starter dev.toml.

With HOURADVANTAGE_ATTEND=on, Time and Attendance runs beside the gateway on the memory store (nothing is kept), to try a clock’s punch to a timecard with no database: hourctl attend tenants create acme --name "Acme", a delivery key, and a sink naming it. Not with —database-url.

hourd dev [OPTIONS] [PACKAGES]
hourd dev <COMMAND>

Arguments:

  • [PACKAGES]: The packages folder. Default: packages.

Options:

  • --database-url <URL>: Keep everything in this Postgres database instead of memory.
  • --reset: Wipe the devices dev.toml lists (the package’s wipe) before they are given the seed.
  • --json: Print each exchange as one JSON object per line on stdout; everything else goes to stderr.

Example:

Terminal window
hourd dev packages

Commands:

  • init: Write a commented starter ./dev.toml, and VS Code tasks.

hourd dev init

Write a commented starter ./dev.toml, and VS Code tasks.

The dev.toml has an endpoint (commented out) for each package in the folder. The VS Code tasks (dev, test, replay) go in ./.vscode/tasks.json unless there is one already. Your own clock’s details (serial, port, captured templates) go in ./dev.local.toml, next to it; init adds it to the folder’s .gitignore.

hourd dev init [PACKAGES]

Arguments:

  • [PACKAGES]: The packages folder. Default: packages.

Example:

Terminal window
hourd dev init