Skip to content

The standby VM

The third VM keeps a copy of the remote site’s applications that is at most 15 minutes old, with a versioned history, and takes over by itself when the remote server has been unreachable for about seven minutes. The warm-standby kit (version 2.2.0, vm/standby/kit/) does the work on both machines. One site serves at a time, and the way back is always manual.

Cloudflare Tunnel (same token on both sides)
| |
cloudflared running cloudflared stopped (started at failover)
| |
+---------------+----------+ site-to-site +-----+----------------------+
| PRIMARY: remote server |<===== VPN ======>| STANDBY: this VM |
| Ubuntu 26.04, GPU | standby PULLS: | Debian 13 arm64, VLAN 6 |
| ws-primary-guard | SSH 22 (read) | ws-watchdog |
| ws-gate (SSH gateway) | status 8099 | ws-sync (every 15 min) |
| role: primary / fenced | | ws-backup (restic, hourly) |
+---------------^----------+ | role: standby / -active |
| internal access +-----^----------------------+
their proxy: server first, this VM as "backup" -+

What has and has not been tested. The kit passes 102 checks in a simulation of both sites (sync, corrupted database dumps, VPN cut, failover, fencing, return, races between the sites). It has never run on real machines. ws-ctl doctor and the drill of part D are that test, and until the drill has passed, treat the standby as unproven.

Three corrections to the kit’s own documents, already applied by this chapter (J18, J19, J20): databases arrive every 15 minutes and are reloaded at most every 60, the folders that carry a sentinel are immich, espocrm, invoiceninja, freshrss and _dumps (the README’s crm is wrong), and this VM’s address is 10.0.6.2.

The kit speaks French. Its messages are quoted here as it prints them.

Why. Same base as the two other VMs: encrypted disk, tagged VLAN, key-only SSH. It holds another household’s photos and business data, so the encryption is not optional here.

Do chapter 5 from step 5.2 to 5.15 with:

Terminal window
export VM=standby VMIP=10.0.6.2

Disk: 256 GB, or 1.5 times the size measured in step 13.2 if that is more. Memory: 4096 MB keeps the copy in sync. During a failover the VM runs Immich with its machine learning on the CPU: if free -h shows swap in use during the drill, raise it to 8192 MB (UTM, VM stopped, Settings > System).

Two differences from chapter 5 on this VM:

  • In step 5.14, the mtu line of verify.sh 6 reports 100 % loss. Policy B3 of step 10.3 blocks this zone from the gateway, on purpose. Check the path with ssh standby 'ping -c2 -M do -s 1468 1.1.1.1 | tail -1' instead: 0% packet loss.
  • Step 5.10’s last line (/srv/stack) is not needed. The kit uses /opt/stack.

Verify. ssh standby verify.sh 6 matches the table of step 5.14 apart from the mtu line, with 1.1.1.2 and 1.0.0.2 as resolvers.

Rollback. Delete the VM in UTM.

Why. J8: neither house sees the other’s network. This VM must reach the internet and, once the tunnel exists, one remote machine. Nothing in your home.

Mac

Terminal window
ssh standby 'for t in 10.0.2.5:53 10.0.2.2:445 10.0.5.2:8123 10.0.5.3:22 10.0.6.1:443 10.0.1.1:443; do
nc -zv -w 2 ${t%:*} ${t#*:} 2>&1 | tail -1; done; nc -zv -w 3 1.1.1.1 443 2>&1 | tail -1'

Verify. Six timeouts, then one succeeded for 1.1.1.1.

Rollback. If any of the six connects, stop: re-check policies B2 to B4 in step 10.3 before any data arrives on this VM.

Why. The kit expects its layout to exist, and its playbook installs Docker’s repository under another file name than chapter 5 did. Two entries for one repository make every apt update complain.

Mac

Terminal window
ssh standby 'sudo mkdir -p /opt/stack /srv/apps /srv/db /srv/restic && sudo chown admin: /opt/stack \
&& sudo rm -f /etc/apt/sources.list.d/docker.list && ls -d /opt/stack /srv/apps /srv/db /srv/restic'
Folder Holds
/opt/stack The remote site’s compose files (a clone of their repository)
/srv/apps/<application> The synchronised data
/srv/db/<application> Database files. Databases arrive as dumps, never as files
/srv/restic The versioned history: 24 hourly, 14 daily, 8 weekly, 12 monthly

Verify. The four paths are listed.

Rollback. sudo rm -rf the four folders.

Now do chapter 13, part 6 (the tunnel and its policies), and come back.

Why. When the remote server is down, so is the remote site’s own monitoring agent. The kit’s alerts must travel by a road that depends on neither site: a Telegram bot of its own, in a group with both owners.

  1. In Telegram, talk to @BotFather: /newbot, a name, a username ending in bot. It answers with a token.
  2. Create a group with the remote owner, add the bot, and send any message in the group.
  3. Mac:
Terminal window
read -rs TOKEN # paste the token, Enter
CHAT=$(curl -s "https://api.telegram.org/bot$TOKEN/getUpdates" | jq -r '[.result[].message.chat | select(.type!="private")][-1].id')
echo "$CHAT" # a negative number
op item get "Telegram bot warm-standby" --vault Infrastructure >/dev/null 2>&1 || \
op item create --vault Infrastructure --category "API Credential" --title "Telegram bot warm-standby" \
credential="$TOKEN" "chat id=$CHAT" >/dev/null
unset TOKEN CHAT

Verify. op read "op://Infrastructure/Telegram bot warm-standby/chat id" prints the negative number.

Rollback. /deletebot in BotFather, and delete the item.

14.5 What the remote owner gives you, and grants for one evening

Section titled “14.5 What the remote owner gives you, and grants for one evening”

Why. The playbook configures both machines in one run, because each needs something from the other: the server gets this VM’s public key, this VM gets the server’s host key. Your Mac has no road to the remote site (step 13.18), so it reaches their server through this VM. That needs an account on their server for the length of the installation, and nothing after it.

Ask the remote owner for three things, and store them:

Terminal window
op item create --vault Infrastructure --category password --title "Remote site NUT monitor" password="<their UPS monitor password>" >/dev/null
op item create --vault Infrastructure --category "Secure Note" --title "Remote site stack env" notesPlain="$(pbpaste)" >/dev/null # their .env, copied to the clipboard
pbcopy </dev/null

The .env carries their Cloudflare tunnel token and the application passwords. It is the same file as on their server: the standby must be able to start the same stacks.

Then, on the evening of the installation, they open the door on their server:

Terminal window
# Run by the remote owner on their server. The key is yours: op read "op://Infrastructure/SSH mac-admin/public key"
echo 'from="10.0.6.2" ssh-ed25519 AAAA...your-public-key... install-window' >> ~/.ssh/authorized_keys
echo "$USER ALL=(ALL) NOPASSWD: ALL" | sudo tee /etc/sudoers.d/99-install-window >/dev/null
ssh-keygen -lf /etc/ssh/ssh_host_ed25519_key.pub # they read you this fingerprint

Mac Accept their server’s host key once, comparing the fingerprint with the one they read to you:

Terminal window
export REMOTE_ADMIN=<their admin user>
ssh -o ProxyCommand="ssh -q standby nc %h %p" $REMOTE_ADMIN@10.6.5.10 'sudo -n true && hostname'

Verify. The fingerprint matches, and the command prints their server’s hostname.

Rollback. Step 14.8 closes the door. To abandon before that, the remote owner runs its two lines now.

Why. The standby starts the same stacks as the server, from the same files. A read-only deploy key lets this VM fetch them and nothing else on GitHub.

Mac

Terminal window
ssh standby 'ssh-keygen -t ed25519 -N "" -C standby-deploy -f ~/.ssh/stack_deploy -q; cat ~/.ssh/stack_deploy.pub'

The remote owner adds that line in their repository: Settings > Deploy keys > Add deploy key, Allow write access off. Then:

Terminal window
ssh standby 'printf "Host github.com\n IdentityFile ~/.ssh/stack_deploy\n IdentitiesOnly yes\n" >> ~/.ssh/config \
&& git clone git@github.com:<owner>/stack.git /opt/stack && ls /opt/stack'
op read "op://Infrastructure/Remote site stack env/notesPlain" | ssh standby 'install -m 600 /dev/stdin /opt/stack/.env'
ssh standby 'cd /opt/stack && docker compose -f compose.yml -f compose.failover.yml -f compose.standby.yml config --quiet && echo STACK-VALID'

Verify. STACK-VALID. The four compose files of step 13.3 are listed.

Rollback. ssh standby 'rm -rf /opt/stack/* /opt/stack/.[!.]* ~/.ssh/stack_deploy*', and the remote owner deletes the deploy key.

14.7 Prepare the playbook on the Mac, and look before changing

Section titled “14.7 Prepare the playbook on the Mac, and look before changing”

Why. --check --diff shows every change the playbook would make on both machines and makes none. On someone else’s server, you read that list with them before the real run.

Mac

Terminal window
brew install pipx && pipx install "ansible-core==2.18.*"
cd ~ && shasum -a 256 -c <(sed "s| .*| $INFRA/vm/standby/kit/warm-standby-2.2.0.zip|" $INFRA/vm/standby/kit/warm-standby-2.2.0.zip.sha256) \
&& unzip -q -o $INFRA/vm/standby/kit/warm-standby-2.2.0.zip -d ~
cd ~/warm-standby-2.2.0/ansible
cp $INFRA/vm/standby/ansible/{inventory.yml,overrides.yml} .
op inject --force -i $INFRA/vm/standby/ansible/vault.yml.tpl -o group_vars/all/vault.yml && chmod 600 group_vars/all/vault.yml
ansible all -m ping
ansible-playbook site.yml -e @overrides.yml --check --diff

The secrets file lands inside the unpacked kit, outside this repository, and step 14.8 deletes it.

Verify. shasum prints OK. The ping answers pong for remote-server and standby-vm. The check run passes the first two plays (base system, Docker, GPU) without a failed task. It then stops at Lire la clé publique, because check mode does not create this VM’s key: that is expected, and the real run goes past it.

Rollback. Nothing was changed. rm -rf ~/warm-standby-2.2.0.

14.8 Install on both machines, then close the door

Section titled “14.8 Install on both machines, then close the door”

Why. One run: base settings, Docker, the kit, the key exchange, the sentinels, the timers. It ends with the kit’s own diagnosis on each machine.

Mac

Terminal window
cd ~/warm-standby-2.2.0/ansible
ansible-playbook site.yml -e @overrides.yml
rm -f group_vars/all/vault.yml

The playbook never restarts a machine. If it reports a pending restart on the remote server, the remote owner plans it.

Then the remote owner closes the door on their server:

Terminal window
sudo rm /etc/sudoers.d/99-install-window && sed -i '/install-window/d' ~/.ssh/authorized_keys

From now on your only access to their server is the kit’s gateway: an account named wsync that can read /srv/apps and ask five questions, and can write only inside a window they open.

Verify.

Terminal window
ssh standby 'sudo ws-ctl version; systemctl is-active ws-watchdog ws-sync.timer ws-backup.timer' # warm-standby 2.2.0, three times active
ssh -o ProxyCommand="ssh -q standby nc %h %p" -o BatchMode=yes $REMOTE_ADMIN@10.6.5.10 true; echo "exit $?" # Permission denied, exit 255
ssh standby 'sudo ssh wsync@10.6.5.10 ws role' # primary
ssh standby 'sudo ls /etc/warm-standby; sudo grep -E "^(ROLE|DB_RESTORE_INTERVAL_MIN|SYNC_PATHS)" /etc/warm-standby/config.env'

The last line shows ROLE=standby, DB_RESTORE_INTERVAL_MIN=60, and the five folders.

Rollback. On each machine: sudo systemctl disable --now 'ws-*', then sudo rm -rf /opt/warm-standby /opt/warm-standby-src /etc/warm-standby /usr/local/bin/ws-ctl. Removing the kit touches neither data nor stacks. On their server, the remote owner sets each labelled container’s restart policy back to what it was.

Why. The two sites see each other through the VPN, and through a second road that does not depend on it: one word served on the public hostname. A VPN cut alone then never triggers a failover.

Remote owner, in the Cloudflare dashboard: Zero Trust > Networks > Tunnels > their tunnel > Public hostnames > Add, placed above the existing rule:

Hostname Path Service
photos.example.org ^/ws/role$ http://ws-status:8080
photos.example.org (none) The existing public proxy, unchanged

The path field of a dashboard-managed tunnel may want the expression without the anchors: if the first form answers 404, try ws/role.

Verify. From anywhere: curl -s https://photos.example.org/ws/role prints primary. Test it again after each cloudflared update: Cloudflare changes how it normalises paths.

Rollback. Delete the rule.

Mac and Remote owner:

Terminal window
ssh standby 'sudo ws-ctl doctor' # on their server: sudo ws-ctl doctor

Verify. Both end with Tout est en ordre. Lines marked INFO are not faults. The usual ÉCHEC lines and their cure:

Line Cure
sentinelle absente dans … (server) The folder did not exist when the playbook ran. On their server: for d in immich espocrm invoiceninja freshrss _dumps; do sudo mkdir -p /srv/apps/$d && sudo touch /srv/apps/$d/.ws-sentinel; done. Never create one in an empty mount point: the sentinel is what tells a missing disk from an empty folder
base … : conteneur … introuvable A name in overrides.yml differs from step 13.2. Correct it, run the playbook again
aucun conteneur étiqueté ws.failover The labels of step 13.3 are missing from the running stacks, or on this VM step 14.11 has not run yet
primaire injoignable par le VPN Policies T1 and T2 (step 13.17), and the two matching ones at the remote site
ws-status ne répond pas The ws-status container is not running: step 14.11 here, step 13.12 there

Then one test message: ssh standby 'sudo ws-ctl test-notify' arrives in the Telegram group.

Rollback. None needed.

14.11 Create the stacks here, and the first copy

Section titled “14.11 Create the stacks here, and the first copy”

Why. refresh pulls the images and creates every container. It starts only what must always run (databases, Redis, the status page) and leaves the applications stopped. The first sync then brings every database and every file across. It can take hours: it is the whole photo library through the VPN.

Mac

Terminal window
ssh standby 'sudo ws-ctl refresh'
ssh -t standby 'sudo systemd-run --unit=ws-first-sync --collect /usr/local/bin/ws-ctl sync && journalctl -fu ws-first-sync'

systemd-run keeps the copy going if your terminal closes. Ctrl-C stops the display only.

Verify.

Terminal window
ssh standby 'sudo ws-ctl status'
ssh standby 'docker ps --format "{{.Names}}: {{.Status}}"; sudo du -sh /srv/apps/*'

The status shows this site as standby, the other as primary, a successful sync a few minutes old, and each database reloaded. Only databases, Redis and ws-status run. The sizes match step 13.2. This is the most sensitive point of the whole kit: Immich’s database uses vector extensions, and a line saying its reload failed must be solved before going further (the same Immich and PostgreSQL image versions on both sides is the first thing to check).

Rollback. ssh standby 'sudo systemctl stop ws-first-sync'. Data already copied stays and the next sync resumes.

14.12 The history, and its password in two houses

Section titled “14.12 The history, and its password in two houses”

Why. A sync is not a backup: a deleted photo is deleted here 15 minutes later. The hourly restic run keeps the versions. Without its password the history is unreadable, so both owners hold it.

Mac

Terminal window
ssh standby 'sudo systemctl start ws-backup.service; sudo restic -r /srv/restic --password-file /etc/warm-standby/restic.pass snapshots | tail -4'

Give the remote owner the password over a channel you both trust: op read "op://Infrastructure/restic standby repository/password".

Verify. One snapshot is listed, and the remote owner confirms the password is in their password manager.

Rollback. ssh standby 'sudo rm -rf /srv/restic/*' starts the history over.

14.13 Internal access follows the failover

Section titled “14.13 Internal access follows the failover”

Why. People at the remote site reach Immich through their proxy, not through the public share. The proxy gets a second destination that nginx uses only when the first does not answer. Since applications are stopped on the site that is not serving, only one ever answers. The kit ships the template, which has not been tried on a real proxy.

Remote owner, on the Raspberry Pi that runs NGINX Proxy Manager:

  1. Create /data/nginx/custom/http.conf from the kit’s snippets/npm-http.conf, with the addresses corrected:
upstream ws_immich {
server 10.6.5.10:2283 max_fails=1 fail_timeout=10s; # their server
server 10.0.6.2:2283 backup; # this VM, through the site-to-site VPN
}

One block per application, with its own port.

  1. In the Immich proxy host, Advanced tab: the content of snippets/npm-advanced-immich.conf.
  2. Check and reload: docker exec <npm container> nginx -t && docker exec <npm container> nginx -s reload.

Verify. nginx -t reports syntax is ok. Immich still opens through its internal name. The failover half is verified in the drill.

Rollback. Empty the Advanced tab and delete http.conf.

Mac

Terminal window
ssh standby 'sudo ssh wsync@10.6.5.10 "rsync --server . immich/"; echo "exit $?"'
ssh standby 'sudo ssh wsync@10.6.5.10 "id"; echo "exit $?"'

Verify. Both are refused (a message containing refusé, a non-zero exit). On their server, journalctl -t ws-gate -n 5 shows the two refusals.

Agree on a date with the remote owner. Until every box below is ticked, the standby is a copy, not yet a failover. Repeat the drill every quarter (chapter 15).

Why. The only proof is pulling the cable.

  • Remote owner unplugs the server’s network cable. Note the time.
  • About 3 minutes: their server, still alive, isolates itself. sudo ws-ctl status on its console shows fenced.
  • About 7 minutes: the Telegram group receives BASCULE EFFECTUÉE.
Terminal window
ssh standby 'sudo ws-ctl status; docker ps --format "{{.Names}}: {{.Status}}"; free -h | sed -n 2,3p'
curl -s https://photos.example.org/ws/role # standby-active
  • An old public share link opens (served by this VM).
  • At the remote site, Immich opens through its internal name (the proxy fell back to this VM).
  • Add one photo and one CRM record while the standby serves.
  • Remote owner plugs the cable back. Their server stays fenced: it sees that the standby serves, and starts nothing.

Rollback. If the failover does not happen, plug the cable back: their server resumes by itself once it sees the internet and no active standby. Read ssh standby 'journalctl -u ws-watchdog -n 80 --no-pager' before trying again.

Why. Two gestures by two people, on purpose: their server accepts writes only inside a window its owner opens.

  • Remote owner, on their server: sudo ws-ctl allow-failback (the window stays open 4 hours).
  • Mac: ssh -t standby 'sudo ws-ctl failback'. Databases and files travel back, their server resumes service, this VM returns to standby.
  • The photo and the CRM record added during the failover are on their server.
  • curl -s https://photos.example.org/ws/role prints primary.
  • ssh standby 'sudo ws-ctl status' shows standby, applications stopped.

Writes made at the remote site in the 15 minutes before the failure, never synchronised, are replaced on the database side. The kit keeps a copy of their database from before the return in /var/lib/warm-standby/dumps/ (*.primaire-avant-retour.*). On the file side nothing is overwritten by something older.

Rollback. If the return fails midway, the standby keeps serving. sudo ws-ctl deny-failback on their server closes the window.

  • Remote owner restarts their server: applications are back in under a minute, after the guard has checked that the standby is not serving.
  • You restart the Mac, log in, vm-up && vm-unlock standby: the VM comes back as standby and starts no application.
  • With the Mac off for more than two hours, their server sends “standby unreachable” to the group. That alert is what tells you both that a power cut left this VM waiting for your login.

Verify. All boxes of 14.15 to 14.17 are ticked. Write the date in the shared incident log.

Situation Where Command
State of both sites Standby sudo ws-ctl status
Before maintenance of their server Standby sudo ws-ctl pause 120, afterwards sudo ws-ctl resume
After they update an application Standby sudo ws-ctl refresh
Planned failover Their server, then standby sudo ws-ctl fence "reason", then sudo ws-ctl failover
Return Their server, then standby sudo ws-ctl allow-failback, then sudo ws-ctl failback
Logs Standby journalctl -u ws-watchdog -u ws-sync -u ws-backup -f
An old file Standby sudo restic -r /srv/restic --password-file /etc/warm-standby/restic.pass snapshots, then restore
New kit version Mac New archive in vm/standby/kit/, steps 14.7 and 14.8 with ws-ctl pause 60 first, and the door of step 14.5 opened again for the run
  • A failure is detected at the level of the machine, the network, Docker or the data disk. An application that runs but answers wrongly does not trigger a failover.
  • With FileVault on (R5), this VM stays down after a power cut at your house until you log in and unlock it. During that time the remote site has no failover, and its server tells the group after two hours.
  • If the remote site is entirely offline, the public share continues from here. Their full internal access to Immich would need a VPN profile towards your gateway, which is not set up (step 13.1).
  • AI features (Ollama) do not run during a failover: a VM has no GPU, and this zone cannot reach the Mac by design.
  • The Mac is a last-resort host: macOS updates, your login after a restart, and ARM, which forces dumps in place of continuous replication. A small dedicated x86 machine would lift these limits, and the same playbook installs on it.

The standby VM holds an encrypted, versioned copy of the remote site’s applications, watches their server over two independent roads, and has taken over and handed back once under your eyes.