Skip to content

What a stand-in has to get right

The home server did not come back from a CPU swap. Two stand-ins went up within two days. What they had to get right came down to order, what a gap in the data means, and who can read a file.

  • Linux
  • MQTT
  • Self-hosting
  • Operations

Status, 25 November: the server is still down. This note will be updated when it is back.

On Sunday 22 November the home server was taken down to swap its CPU for a Ryzen 9 9950X. Socket pins on the AM5 board were damaged during the swap, and the machine has been down since. A new motherboard is in transit. It will be built and tested at the workshop first, and only then go back to the home server’s site, a 2.5-hour trip.

The server carried the MQTT broker for every sensor and the Zigbee control loop, the sensor database (TimescaleDB), the password manager and a website. The password manager and the website moved to a small server elsewhere on 23 November and stay there. The VPN also ran through the server, so the machines that remained could no longer reach each other the old way. The stand-ins are why the trip can wait for a working machine instead of a rushed one.

Two stand-ins took over: the MQTT broker, with a recorder, on the small server, and the sensor database, rebuilt on a second machine that is switched off at night. What follows is what they had to get right. The figures are from their READMEs and the commit log, written while the work was done. They have not been re-run for this note.

1. The recorder has to be running before the port opens

The small server took over the broker’s name, with the same user and password, so clients needed no change, apart from one machine that goes out through a VPN and needed a hosts-file pin. A recorder writes every message to a file (all but the Zigbee bridge’s own topics), so the data can be replayed into the real broker later.

The sensor Pi had been buffering air-quality readings since 08:40 UTC on 22 November, with no size cap. A buffer like that empties into the first broker that accepts. If the port had opened before the recorder was subscribed, the whole flush would have gone to a broker with no subscriber and been gone. The installer therefore starts the recorder, proves it writes, and only then opens the port. The firewall rule is deliberately live-only, not in the boot firewall, because the stand-in is temporary: a reboot drops it, and the installer has to be run again. If no Zigbee message has been recorded for ten minutes, on two checks in a row (they run every five minutes), a mail goes out.

2. The hole is per sensor, not per outage

The sensor database was rebuilt from the nightly dump and then fed from the recording. The second machine is switched off at night, so “connection refused” has to be read as stale, not zero. What the rebuilt copy holds, in UTC:

WindowWhat the copy holds
up to 21 Nov 06:47the dump
21 Nov 06:47 to 22 Nov 08:35nothing, for any sensor
22 Nov 08:35 to 23 Nov 12:349 sensors, from replayed buffers; four more with a single row each at 12:07; nothing for the rest
from 23 Nov 12:34the recording, 172 sensors

The first gap is the age of the dump, not the outage: the first buffered readings are from about 08:35 to 08:40 UTC on 22 November, so the server was running until about then. These are holes in the rebuilt copy, not lost data: the missing rows should still be on the server’s own disks, up to the outage (not checked while the server is down). The README lists the sensors one by one instead of giving one outage window, because a reader that treats “no data” as zero would be wrong for most of them.

3. The stand-in’s own first reload took it down

On 23 November the broker was started, and a minute later its password file was set to root-only, mode 0600. Mosquitto 2.0.22 opens that file as its own user, on start and on a reload, and nothing had tried since the change. The first reload came the next morning, at 08:15:58 local time (07:15:58 UTC). Every client was refused, and the restart that followed failed until the file was made readable: 6 minutes 36 seconds in all, ending 08:22:34 local. Site messages in that window were lost where their publishers do not buffer. The reload script now refuses to run when the broker’s user cannot read the file.

4. The retire order pointed back at the stand-in

A review of the previous day’s moves found the retire order, the steps for moving back to the real server, wrong. A hosts-file pin on the second machine still sent the broker’s name to the stand-in, and the first version of the replay script defaulted to that name, so replaying “into the real broker” would have written into the stand-in itself. The order was rewritten, and the replay was tested ahead of time: the timescale path found 251,071 of 251,071 rows present in the stand-in copy, and the MariaDB path ran against a scratch instance, adding 4,280, 41 and 31 rows on the first commit and 0 on the second. Neither test touched the real server, which is down. On the MariaDB path a second run added nothing, and the script is written to be safe to run twice.

What the stand-ins cannot do

A broker restart loses what arrives while it is down, unless the publisher buffers it. The HAN meter’s live stream was lost until the recorder started catching it, about 12:39 UTC on 23 November. Its hourly energy is kept on the reader for only 24 hours, and an hourly cron on a sensor Pi has saved it since the afternoon of 23 November, so some hourly values from the first hours of the outage may be gone. The README does not say how many. It lists these limits, so nobody discovers them during the replay.

The same lesson ran through both stand-ins: they make promises about order and about their gaps. What must run before what, which target a replay writes to, who can read which file, and what a missing row means are written down in the install and retire steps. The retire order was fixed after a review; the permissions fault was found by the outage itself.

← all notes

esc
↑↓ nav ↵ open esc close