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).
| Containers | The container image, which the Compose and Kubernetes setups run. |
| Docker Compose cluster | HAProxy in front of N instances, Postgres and a Valkey. |
| Kubernetes | A Deployment and HPA behind a Service of type LoadBalancer (externalTrafficPolicy: Local), external Postgres. |
| systemd | One instance as a Linux service. |
| Windows service | One 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.
Containers
Section titled “Containers”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,hourctlandhouradm. It has no entrypoint. Its default command ishourd 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 user10001: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_URLandHOURADVANTAGE_SECRET_KEY. The admin API listens on0.0.0.0:9090. It requires a login:HOURADVANTAGE_ADMIN_USERNAMEandHOURADVANTAGE_ADMIN_PASSWORD_HASH. Each of these also has a_FILEform. 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 healthcheckasks/livezon 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 --readyasks/api/readyinstead, as the Compose setup does.
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.0systemd
Section titled “systemd”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 0600HOURADVANTAGE_DATABASE_URL=postgres://houradvantage:secret@db/houradvantageHOURADVANTAGE_SECRET_KEY=<houradm gen-secret-key>HOURADVANTAGE_ADMIN_USERNAME=adminHOURADVANTAGE_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.
Windows service
Section titled “Windows service”From an elevated prompt:
# admin API on 127.0.0.1:9090houradm service install --database-url postgres://houradvantage:secret@db/houradvantagehouradm service install --admin-listen 127.0.0.1:9191 --database-url ...# Time and Attendance beside Connect, and a variable for the serverhouradm service install --attend --env HOURADVANTAGE_ENVIRONMENT=production --database-url ...houradm service startsc.exe query houradvantagehouradm service stophouradm service uninstallThe 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):
$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%\houradvantageholds 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 onlylogs. - Environment. The service is given the same variables a container is, in the
Environmentvalue of its registry key. Three of them name files in its folder:HOURADVANTAGE_DATABASE_URL_FILE,HOURADVANTAGE_SECRET_KEY_FILEandHOURADVANTAGE_ADMIN_PASSWORD_HASH_FILE. The registry is readable by every local account, so secrets stay out of it. The other variables areHOURADVANTAGE_ADMIN_USERNAME=admin, andHOURADVANTAGE_ADMIN_LISTENwhen--admin-listenis not the default. - Time and Attendance.
--attendruns it beside Connect on this instance (HOURADVANTAGE_ATTEND=on). Without it the service is Connect only. Give--attendor--env HOURADVANTAGE_ATTEND=..., not both. - Other variables.
--env NAME=VALUEgives the service a variable the server reads. Repeat it for more, once for each name. It takesHOURADVANTAGE_ADVERTISE_ADDR,HOURADVANTAGE_ALLOW_PLAIN_TEXT_SECRETS,HOURADVANTAGE_ATTEND,HOURADVANTAGE_CPUS,HOURADVANTAGE_ENVIRONMENT,HOURADVANTAGE_INSTANCE_ID,HOURADVANTAGE_PRODUCTIONandHOURADVANTAGE_SECRET_KEYS_OLD_FILE, and nothing else.HOURADVANTAGE_SECRET_KEYS_OLD_FILEis 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(orHOURADVANTAGE_DATABASE_URLwhere install runs) is written todatabase-urlin its folder on every install. - Secret key. Install makes a key in
secret-keyin 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 toadmin-password-hashin its folder and prints the password once. A reinstall keeps it.hourctltakes the password asHOURADVANTAGE_ADMIN_PASSWORD, withHOURADVANTAGE_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.
installrefuses while the service exists. To change a flag or a variable, runhouradm service uninstall(it stops the service first). Then runinstallagain with every flag you want. The service’s environment is set anew from the flags of that install. So a--attend,--admin-listenor--envgiven 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 stopwaits for the service up to 40 seconds. When the machine shuts down, the system waits up to 55 seconds for it.
A second Windows instance
Section titled “A second Windows instance”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:
New-Item -ItemType Directory -Force $env:ProgramData\houradvantageCopy-Item .\secret-key, .\admin-password-hash $env:ProgramData\houradvantagehouradm service install --admin-listen 0.0.0.0:9090 --database-url postgres://houradvantage:secret@db/houradvantageThe 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:
New-NetFirewallRule -DisplayName "Hour Advantage admin" -Direction Inbound -Protocol TCP -LocalPort 9090 -Action AllowThe 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.
Changing the secret key on Windows
Section titled “Changing the secret key on Windows”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:
- On each instance,
houradm service uninstall. - 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) insecret-key. houradm service install ... --env HOURADVANTAGE_SECRET_KEYS_OLD_FILE=C:\ProgramData\houradvantage\old-secret-keyswith every other flag of that instance, andhouradm service start. Install closes the folder to everyone else, the old keys file included. Do the instances one at a time.- Once every instance runs with the new key and has sealed everything again, uninstall and install each without the
--env. Then deleteold-secret-keys.