User Guide · Administer · Controller HA

Controller high availability

A self-hosted Jarwis installation can run two or more controllers in front of one shared database. One controller is the leader and does all the work. The others stand by and take over automatically when the leader stops, so backups, schedules, alerts and agents keep running while a controller host is down.

Self-hosted only Controller HA is for self-hosted installations (JARWIS_MODE=onprem). The Jarwis cloud service runs its own redundancy.

How it works

  • One leader at a time. The controllers compete for a lease row in the shared database. The controller that holds it is the leader. It runs the console, the API, the agent connections, the task runner, the scheduler and the alert evaluator.
  • Standbys forward requests. A standby answers its own health check and forwards every other request, including agent connections, to the leader. Pointing a browser at a standby still works.
  • Automatic takeover. The leader renews its lease every few seconds. If it stops renewing (the host crashed, the process was killed, the network split), a standby takes the lease once it expires. By default that takes up to about 15 seconds. The new leader starts with the next fencing token.
  • No split brain. A controller that loses the lease stops itself immediately, before it can start or finish any work. Its service manager restarts it as a standby. Because the lease uses the database clock, the controllers' own clocks do not matter.
  • Interrupted tasks. A task that was running on the old leader is marked failed with the reason "controller restarted or failed over (HA)". Retry it from the cluster page. Jarwis cleans up the half-finished attempt and runs it again from the start.

Set up two controllers

  1. Use one MySQL or MariaDB database for both controllers, ideally a replicated or clustered one, so the database is not a single point of failure.
  2. Give every controller the same JARWIS_DATABASE_DSN, JARWIS_SECRET_KEY and JARWIS_JWT_SECRET. Credentials and sign-in sessions only work across controllers when these match.
  3. Turn HA on in each controller's environment file:
    JARWIS_MODE=onprem
    JARWIS_HA_ENABLED=true
    JARWIS_HA_ADVERTISE_URL=http://10.0.0.11:8080   # this controller, as the others reach it
    JARWIS_HA_NODE_ID=controller-1                  # optional, shown in Settings
    JARWIS_TRUSTED_PROXIES=10.0.0.12                # the other controller(s)
  4. Make sure the service restarts on exit (Restart=always in the systemd unit). A controller that loses the lease exits with code 3 and must come back as a standby.
  5. Start the controllers. The first one to start becomes the leader; the second starts as a standby.
VariableDefaultMeaning
JARWIS_HA_ENABLEDfalseTurns controller HA on. Needs JARWIS_MODE=onprem.
JARWIS_HA_ADVERTISE_URLrequiredThe URL other controllers use to forward requests to this one.
JARWIS_HA_NODE_IDhost name and portThe name shown for this controller.
JARWIS_HA_LEASE_TTL15sHow long a lease lasts without renewal (at least 3s). Shorter means faster takeover.
JARWIS_HA_RENEW_INTERVALa third of the TTLHow often the leader renews and the standbys try to take over. Must be under half the TTL.

Agents

Agents connect out to the controller, so they need to find the leader after a takeover. Choose one of these:

  • A virtual IP (recommended). Point every agent at the VIP with JARWIS_SERVER_URL=http://10.0.0.10:8080 and let Keepalived move it (see below).
  • A list of controllers. Add the other controllers to the agent's agent.env: JARWIS_SERVER_URLS=http://10.0.0.12:8080 (comma separated). When the connection drops, the agent tries the next address. A standby forwards the connection to the leader, so any address in the list works while a leader exists.

Keep a virtual IP on the leader

Each controller answers GET /health/leader with 200 when it is the leader and 503 when it is a standby. A Keepalived health check on that URL keeps the VIP on the leader:

vrrp_script jarwis_leader {
    script "/usr/bin/curl -fsS -m 2 -o /dev/null http://127.0.0.1:8080/health/leader"
    interval 2
    fall 2
    rise 2
}

Use state BACKUP and nopreempt on every controller so the VIP follows the lease, not the Keepalived priority. A complete example ships with Jarwis as deploy/ha/keepalived.conf.example. A load balancer can use the same URL as its health check. Plain GET /health answers 200 on every running controller, leader or standby.

See the HA status

As an admin or owner, open Settings → Controller HA. It shows the current leader and its address, the fencing token, when the lease expires, and every controller that has reported in, with its role, version and last heartbeat. A controller that has not reported for a while is marked stale. The section only appears on self-hosted controllers.