High availability (warm standby)
For a switchover in minutes instead of hours you run two nodes: the primary (database writable, full
stack, holds the shared address, the VIP) and the standby (database as a streaming replica, only postgres and
backend run). The database is replicated over TLS and also contains the logs. Switching happens only by hand on the
standby (opnexus ha promote); there is deliberately no automatic failover, because two nodes without a third witness cannot
tell an outage from a network partition, and two primaries with access to the same firewalls do more
harm than a failed OPNexus (the firewalls keep running unchanged without OPNexus).
Prerequisites: two Linux servers in the same network (L2), on both OPNexus of the same version from the release bundle,
SSH key login from the primary to the standby (as root), openssl, NTP on both, a free address as VIP (ha init checks that nobody uses it). On the
standby enough space for the database (database plus reserve; the server's disk warning applies on both nodes).
The HA commands run on the host, not in the updater container (VIP and cron need the host).
Setting up without SSH (recommended, from 1.37): on the standby run ./opnexus ha prepare. This switches on the updater and the HA gate
(port 8445) and prints a pairing code, valid for 30 minutes and single use. On the primary:
./opnexus ha init --code 'OPNX1-…' --vip 192.168.2.22/24 # --node a --peer-node b --node-ip --vip-dev --yesThe command checks beforehand version, release mode, space on the partner, whether the VIP is free and whether the partner's proxy answers, then pairs both nodes (the
partner's certificate must match the pin in the code before anything is sent) and sets up the pair. Prerequisites: same version on both nodes, NTP,
port 8445 open between the nodes (access lists), openssl on the primary (for the replication certificate). SSH keys, root access between the nodes and the cron are no longer needed:
fencing, takeover, resync, sync and update run through fixed verbs of the agent, the secrets sync and the VIP follow-up through its timer.
The gate listens only on the node's address (line HA_GATE_BIND in the .env, set by the tool) and runs without root. It forwards only the paths for pairing and the partner verbs to the updater; everything else answers 404, without the secret 401. The updater thus has more tasks than
updating and is still reachable only from the Compose network (backend) and through the gate (partner). If setup fails after pairing, a new code is enough
(ha prepare on the standby); the half-finished pairing is discarded.
Setting up and operating in the interface (from 1.37): Settings › System › High availability. On the future standby first log in and choose "Prepare this server as standby": the card shows the pairing code
(30 minutes, single use). On the future primary "Set up HA": paste the code, enter the shared address (VIP) with the prefix length (name, address and interface of the node are suggested and can be adjusted under "change"),
"Check prerequisites" (changes nothing: version, space, VIP free, partner reachable), then "Set up now" (the page shows the log; the backend restarts in the process, the dialog stays open). With a pair the card offers
Sync now, Rebuild standby (after a switch or if the standby is behind), Switch to partner (planned, without data loss) and Dissolve HA (the partner is emptied and afterwards is an empty
single installation with setup assistant). Every action asks for the logged-in administrator's password. If the card shows "Agent not reachable", the updater container is not running (profile updater). Notification
"HA agent not responding": this node's agent has been silent for over 5 minutes (check the updater container).
Switching an existing SSH pair to the agent: bring both nodes to the same version with agent (./opnexus ha update), then on one node ./opnexus ha migrate-agent (port 8445 open between the nodes). The command uses SSH one last time,
pairs both gates, checks them with a ping and only then removes the cron of both nodes; if anything fails, the SSH pairing stays in place. Roles, epoch and data do not change.
Setting up via SSH (older variant, stays for at most two minor versions): on the future primary; the standby is overwritten in the process:
./opnexus ha init [email protected] --vip 192.168.1.22/24 # --node-ip, --peer-ip, --vip-dev, --peer-dir, --node, --peer-nodeha init creates a cluster CA and a server certificate for the database (SAN: both nodes and the VIP), sets up on the
primary the replication role, pg_hba.conf, the replication slot and the cap for retained WAL (max_slot_wal_keep_size
= 4 GB), publishes the database port on the LAN address (file docker-compose.ha.yml, a short restart of the
database), creates a shared SSH key for both directions, builds the standby from a base backup, sets the VIP and
sets up the cron (/etc/cron.d/opnexus-ha: sync every 5 minutes, VIP after a reboot). OPNEXUS_SITES and
FRONTEND_ORIGIN then contain the VIP; the proxy CA is the same on both nodes, so browsers trust both.
Where the state lives: .opnexus-ha/state in the installation directory (role, node, addresses, VIP, replication password; readable by root only). Only the tool maintains this
file; you never have to touch the .env for it. The .env contains only COMPOSE_FILE (so that a docker compose up -d run by hand does not remove the
database port) and a derived line HA_ROLE, which older tools need; if they differ, the file wins. Pairs from earlier versions are migrated automatically on the
first HA command. The file does not belong in backups or migrations (migrate-host): a restored server is not a pair node.
Operation:
./opnexus ha statusshows both nodes: role, epoch, version, replication lag, slot fill level, age of the last secrets sync, clock offset and whether the secret file exists for every firewall and every two-factor account../opnexus ha sync(on the primary, otherwise from cron) transfers the secrets (they are not in the database), the overlay, new configuration backups of the firewalls, the proxy CA and a fixed list of shared.envsettings (login, cookie, update check, certificate check; ports, addresses, registry and profiles stay per node). The secrets are therefore up to 5 minutes old;ha promotefirst checks that a file exists for everything in the database.- One-click updates in the web interface are blocked as long as HA is set up, and so is
opnexus update. Updating is done with./opnexus ha update [VERSION]on the primary: first the standby (pull images, verify signature, restart backend; it never migrates), then the primary as usual (backup, migration, which flows to the standby via replication), finally the check that both nodes have the same version and revision and the standby is streaming. An automatic rollback on the primary restores a dump; the standby follows by itself, the log history is empty on both afterwards.
Taking over in the browser (standby): the full stack runs on the standby. Whoever opens its address (not the VIP) lands on /standby. There a local
administrator logs in (password and, if set up, the authenticator app code; recovery codes do not work on the standby; the login is valid for 15 minutes). The page shows the state
of the pair and the button "Take over now". If the partner's agent is reachable, the partner is stopped first (like ha promote). If the pair still runs over SSH (without agent pairing), the page cannot stop the partner and does not offer takeover: then ./opnexus ha promote in the terminal or beforehand ./opnexus ha migrate-agent. If the partner does not answer at all, the page requires the
typed sentence alter Primaer ist aus ("old primary is off"); the prerequisite is that it is really switched off. If it still answers as leader (only the connection to its agent is missing), the page refuses the
takeover. After about a minute this node is the primary; who took over appears in the audit log. The terminal (./opnexus ha promote) remains the equivalent way back, even if no
local administrator account with a synchronised second factor exists (pure SSO accounts cannot log in on the standby).
VIP and old primary: the agent follows up the VIP every minute. It belongs to the primary only as long as its backend is not blocked by the partner watchdog (fenced) and the partner does not answer as
leader with a higher epoch; an old primary after promote --force therefore releases it by itself as soon as the new one is reachable. A single failed query does not count as
"no leader" (it is asked twice). ha sync synchronises the overlay and GUI profile (COMPOSE_PROFILES) together with GUI_PORTS/OVERLAY_PORT to the partner, so that after a switch wg-hub and
gui-gateway run there; updater and ha remain the business of the respective node.
Switching (the primary has failed or is to be serviced): on the standby
./opnexus ha promoteThe tool checks replication state and secrets, first stops the old primary (fencing: stop all services, release the VIP,
HA_ROLE=fenced), promotes the database, increases the epoch, restarts the backend and the other services and
sets the VIP. If the old primary is not reachable, it aborts: then switch it off safely (power, hypervisor), verify that it is
off, and call ./opnexus ha promote --force (requires the typed confirmation "alter Primaer ist aus" / "old primary is off"). In the lab
the VIP was reachable again after about 12 seconds, the background services (alarms, scheduled maintenance) run after about half a minute.
The old primary is brought back as the new standby with ./opnexus ha resync (run there); there is no need to switch back.
After a forced switch (--force) HA_ROLE=primary is still set there; then ./opnexus ha resync --from-peer applies. It runs only if the
partner has a higher epoch, i.e. demonstrably took over later, and otherwise leaves everything untouched. ha promote --force refuses as long as the
partner still answers as leader at its address (SSH alone is then merely disturbed): switch it off safely first.
Alarms and metrics: the leader checks five things (a switch under Settings › Notifications, on by default): standby
has not been streaming for 5 minutes, replication lag over 64 MB or 60 s, replication slot retains more than 50 % of the cap or
is missing/lost ("Rebuild standby"), last secrets sync older than an hour, partner runs as a second primary
(split brain). On the dashboard they appear among the health problems. For Prometheus there are opnexus_ha_role, opnexus_ha_epoch,
opnexus_ha_replication_lag_bytes, opnexus_ha_slot_retained_bytes, opnexus_ha_sync_age_seconds and opnexus_ha_split_brain (even a
fenced node answers the scrape). Settings › System shows the card "High availability" with the state of the pair.
Protection against two primaries: every backend asks the partner (https://PARTNER/api/health, with its port for a different PROXY_HTTPS_PORT; ha init checks the address beforehand) for role and epoch before it starts the
background services, and then every 30 seconds. If the partner reports leader with the same or a higher epoch, this
node runs in the state fenced without background services and reports split_brain, and it rejects all modifying API calls with 503 (reading and logging in continue); an unreachable partner is no objection
(stopping it is the job of fencing). After a restart a primary does not set the VIP as long as the partner is leader.
Running work during a switch: unconfirmed changes with an expired window are reverted by the new primary. Overdue rollout steps are postponed in the 10 minutes after a switch instead of being discarded as "not started". Scheduled maintenance that was in the middle of starting at the time of the outage is closed by the new primary after 15 minutes as "interrupted" (the operation stays blocked until someone has checked the firewall; a rollout pauses).
Limits: IPv4, one network (L2) with a shared VIP, exactly two nodes. Replication is asynchronous: the last seconds before an
outage may be missing (drift detection finds deviations on the firewalls). If the standby is down longer than the
retained WAL lasts (cap 4 GB, about 12 hours on average), it loses its slot; the primary keeps running, and
ha resync rebuilds the standby. Firewalls that open their API only to certain senders must allow both node addresses.
What is not in the dump:
- The tables of log collection and system load (schema only). After a restore they are empty and fill from the firewalls.
- Secrets (API secrets, VPN and certificate keys, two-factor): they
live in the separate volumes. For a complete backup use
./opnexus backup --full(see above).
Restoring into an empty database (not with --clean into an
existing one):
docker compose exec postgres-backup ls /backups # list dumps
docker compose cp postgres-backup:/backups/<file>.dump /tmp/restore.dump
docker compose cp /tmp/restore.dump postgres:/tmp/restore.dump
docker compose stop backend frontend
docker compose exec -e PGPASSWORD=<PASSWORD> postgres \
psql -U opnexus -d postgres -c "DROP DATABASE opnexus; CREATE DATABASE opnexus OWNER opnexus;"
docker compose exec -e PGPASSWORD=<PASSWORD> postgres \
pg_restore -h localhost -U opnexus -d opnexus /tmp/restore.dump
docker compose up -d backend frontendA dump can only be restored into a Postgres of the same major version
(currently 16). If you roll back after an update, it is best to use ./opnexus rollback.