Skip to content

Deploying

This page lists the ways to run Hour Advantage, from one container to a cluster. It also covers the container image, systemd and the Windows service.

Whatever runs it, an instance needs only Postgres and a few environment variables (reference). The setup, the packages and everything devices send are kept in the database. So an instance keeps no files worth keeping. Once it runs, push the packages and set up listeners and endpoints (quick start).

ContainersThe container image, which the Compose and Kubernetes setups run.
Docker Compose clusterHAProxy in front of N instances, Postgres and a Valkey.
KubernetesA Deployment and HPA behind a Service of type LoadBalancer (externalTrafficPolicy: Local), external Postgres.
systemdOne instance as a Linux service.
Windows serviceOne instance as a Windows service, with its own virtual account.

Several instances can share one database, all active, behind any load balancer. See operations for running a cluster. See networking for ports, paths and the load balancer in front.

The container image comes with the Hour Advantage distribution. Load or pull it as your distribution provides, under its name and version (houradvantage:0.1.0 in these pages).

  • Programs. The image carries hourd, hourctl and houradm. It has no entrypoint. Its default command is hourd run. To run another command, name a program. For example: docker run --rm houradvantage:0.1.0 houradm gen-secret-key. It runs as the non-root user 10001:10001.
  • Packages. The official package bundles are in /usr/share/houradvantage/packages. They are built and tested with the programs. The server does not read them from there. Push them once it runs (docker exec <container> sh -c 'hourctl pkg push --activate /usr/share/houradvantage/packages/*.tar.gz', with the admin login in its environment). The Compose and Kubernetes examples do this with a one-shot step.
  • Settings. Give the container HOURADVANTAGE_DATABASE_URL and HOURADVANTAGE_SECRET_KEY. The admin API listens on 0.0.0.0:9090. It requires a login: HOURADVANTAGE_ADMIN_USERNAME and HOURADVANTAGE_ADMIN_PASSWORD_HASH. Each of these also has a _FILE form. That form names a file holding the value.
  • Logs and stopping. Without a terminal the log is JSON lines on stdout. A stop drains for 6 s. So give the container a stop timeout above that, and above the attendance workers’ (about 20 s with them running). The examples here use 40 s and 60 s.
  • Health check. hourd healthcheck asks /livez on the admin port. That check does not depend on the database. So a database outage does not mark every container unhealthy at once. hourd healthcheck --ready asks /api/ready instead, as the Compose setup does.
Terminal window
docker run --rm -e HOURADVANTAGE_DATABASE_URL=postgres://... \
-e HOURADVANTAGE_ADMIN_USERNAME=admin -e HOURADVANTAGE_ADMIN_PASSWORD_HASH='$argon2id$...' \
-e HOURADVANTAGE_SECRET_KEY=... -p 8080:8080 houradvantage:0.1.0

packaging/systemd/houradvantage.service runs hourd run as user houradvantage, with hardening, and restarts on failure. Its comments list the setup steps. There is no install command on Linux. The service writes no files and reads no packages from disk. Push the bundles once it runs (packages).

The database URL, the secret key and the admin login go in a root-only environment file. systemd reads that file before it drops to the service’s user. The file is required. The unit’s EnvironmentFile= has no leading -. So without the file the service does not start, and it says why:

# /etc/houradvantage/houradvantage.env, mode 0600
HOURADVANTAGE_DATABASE_URL=postgres://houradvantage:secret@db/houradvantage
HOURADVANTAGE_SECRET_KEY=<houradm gen-secret-key>
HOURADVANTAGE_ADMIN_USERNAME=admin
HOURADVANTAGE_ADMIN_PASSWORD_HASH=<houradm hash-password>

Logs go to the journal: journalctl -u houradvantage -f. Stdout is not a terminal there, so each line is one JSON object. journalctl -o cat shows them as they are.

From an elevated prompt:

Terminal window
# admin API on 127.0.0.1:9090
houradm service install --database-url postgres://houradvantage:secret@db/houradvantage
houradm service install --admin-listen 127.0.0.1:9191 --database-url ...
# Time and Attendance beside Connect, and a variable for the server
houradm service install --attend --env HOURADVANTAGE_ENVIRONMENT=production --database-url ...
houradm service start
sc.exe query houradvantage
houradm service stop
houradm service uninstall

The service commands exist only on Windows. The service is named houradvantage. sc.exe query houradvantage (or services.msc) shows its state.

install registers the server, hourd.exe, with the service manager. hourd.exe must be next to houradm.exe. The service manager starts it as hourd service (by its absolute path). install also sets the service to start with Windows. It sets the service to restart after a failure (5 s, 30 s, 120 s).

The service reads no package files: packages are in the database. Push the official bundles from the distribution once it runs. Do it from a machine that reaches the admin API, in the folder that holds them (packages):

Terminal window
$env:HOURADVANTAGE_ADMIN_USERNAME = 'admin'; $env:HOURADVANTAGE_ADMIN_PASSWORD = '<printed by install>'
hourctl pkg push --activate (Get-ChildItem *.tar.gz).FullName
  • Account. The service runs as its own virtual account, NT SERVICE\houradvantage. It has no password and no rights beyond what install grants it. It is not LocalSystem.
  • Its folder. %ProgramData%\houradvantage holds the service’s secret files and its log, nothing else. Install makes it open only to that account, SYSTEM and the Administrators. Nothing is inherited from ProgramData, where every user may read. The service may read everything in it and change only logs.
  • Environment. The service is given the same variables a container is, in the Environment value of its registry key. Three of them name files in its folder: HOURADVANTAGE_DATABASE_URL_FILE, HOURADVANTAGE_SECRET_KEY_FILE and HOURADVANTAGE_ADMIN_PASSWORD_HASH_FILE. The registry is readable by every local account, so secrets stay out of it. The other variables are HOURADVANTAGE_ADMIN_USERNAME=admin, and HOURADVANTAGE_ADMIN_LISTEN when --admin-listen is not the default.
  • Time and Attendance. --attend runs it beside Connect on this instance (HOURADVANTAGE_ATTEND=on). Without it the service is Connect only. Give --attend or --env HOURADVANTAGE_ATTEND=..., not both.
  • Other variables. --env NAME=VALUE gives the service a variable the server reads. Repeat it for more, once for each name. It takes HOURADVANTAGE_ADVERTISE_ADDR, HOURADVANTAGE_ALLOW_PLAIN_TEXT_SECRETS, HOURADVANTAGE_ATTEND, HOURADVANTAGE_CPUS, HOURADVANTAGE_ENVIRONMENT, HOURADVANTAGE_INSTANCE_ID, HOURADVANTAGE_PRODUCTION and HOURADVANTAGE_SECRET_KEYS_OLD_FILE, and nothing else. HOURADVANTAGE_SECRET_KEYS_OLD_FILE is a file of old secret keys, for a key being changed. The registry shows its values to every local account, so a secret is never given this way.
  • Database URL. --database-url (or HOURADVANTAGE_DATABASE_URL where install runs) is written to database-url in its folder on every install.
  • Secret key. Install makes a key in secret-key in its folder the first time. A reinstall keeps it. Back it up. Other instances sharing the database need the same key.
  • Login. Every local account can reach 127.0.0.1. So the service’s admin API always asks for a login, and the service refuses to start without one. The first install makes one: user admin, a random password. It writes its hash to admin-password-hash in its folder and prints the password once. A reinstall keeps it. hourctl takes the password as HOURADVANTAGE_ADMIN_PASSWORD, with HOURADVANTAGE_ADMIN_USERNAME=admin.
  • Log. The service’s log goes to %ProgramData%\houradvantage\logs\houradvantage.<date>.log. It is one JSON object per line, a file a day, the newest 30 kept.
  • Changing what was installed. install refuses while the service exists. To change a flag or a variable, run houradm service uninstall (it stops the service first). Then run install again with every flag you want. The service’s environment is set anew from the flags of that install. So a --attend, --admin-listen or --env given before and not given now is gone. The folder is left as it is. The secret key and the login are kept, and the database URL is the one given now.
  • Stopping. A stop control is shown as stop-pending at once. The server is given 30 seconds to drain and shut down. houradm service stop waits for the service up to 40 seconds. When the machine shuts down, the system waits up to 55 seconds for it.

Instances that share a database need the same secret key. For the same login, they need the same admin password hash. Install makes both in the service folder only when they are not there. So put the first instance’s files there before installing the second:

Terminal window
New-Item -ItemType Directory -Force $env:ProgramData\houradvantage
Copy-Item .\secret-key, .\admin-password-hash $env:ProgramData\houradvantage
houradm service install --admin-listen 0.0.0.0:9090 --database-url postgres://houradvantage:secret@db/houradvantage

The files were copied from the first instance’s %ProgramData%\houradvantage by a means you trust. The key opens every secret in the database.

install then closes the folder to everyone but the service, SYSTEM and the Administrators, copied files included. It keeps the two files. It prints no password, since the login is the first instance’s.

The admin API listens on loopback unless --admin-listen says otherwise. To reach this instance’s from another machine, give an address as above. Put a TLS proxy in front of it (reaching the admin API). Let the port in through Windows Defender Firewall:

Terminal window
New-NetFirewallRule -DisplayName "Hour Advantage admin" -Direction Inbound -Protocol TCP -LocalPort 9090 -Action Allow

The device and API listeners need a rule for their own ports in the same way. houradm service uninstall and install again with the other flags change an instance. See above.

The steps are those of changing the key. On Windows the key is the file secret-key. The old key goes in a file the service can read, named by HOURADVANTAGE_SECRET_KEYS_OLD_FILE:

  1. On each instance, houradm service uninstall.
  2. In %ProgramData%\houradvantage, keep the old key in a file next to the key (Copy-Item secret-key old-secret-keys). Then put the new key (houradm gen-secret-key) in secret-key.
  3. houradm service install ... --env HOURADVANTAGE_SECRET_KEYS_OLD_FILE=C:\ProgramData\houradvantage\old-secret-keys with every other flag of that instance, and houradm service start. Install closes the folder to everyone else, the old keys file included. Do the instances one at a time.
  4. Once every instance runs with the new key and has sealed everything again, uninstall and install each without the --env. Then delete old-secret-keys.