| 1 | # The other half of the restore drill. carlos-restore-verify.service proves |
| 2 | # every database named in /etc/litestream.yml; that config deliberately OMITS |
| 3 | # hibernating instances, because the activator's embedded litestream owns |
| 4 | # their replication under its lease and a second replicator on the same WAL |
| 5 | # would corrupt the replica. The consequence, until this unit existed, was |
| 6 | # that the fleet's largest set of app databases was the one set nobody ever |
| 7 | # drilled — the first thing to learn whether a hibernating tenant's replica |
| 8 | # restores clean was a real user's wake. |
| 9 | # |
| 10 | # This restores each of those replicas into a private tmp, integrity-checks |
| 11 | # it, and publishes a per-host verdict to the deployment bucket |
| 12 | # (control/restore-verify.json) so the result is readable WITHOUT a session on |
| 13 | # this box. A damaged replica leaves the unit 'failed'; a replica the pass |
| 14 | # could not reach is recorded 'unverified' and does not fail the run. |
| 15 | # |
| 16 | # Inert until /etc/carlos/host.env carries CARLOS_HIBERNATE_BUCKET — a box |
| 17 | # with no hibernating instances prints that and exits 0. |
| 18 | [Unit] |
| 19 | Description=carlos hibernate-verify (restore-drill the activator-owned replicas) |
| 20 | After=network-online.target carlos-edge.service |
| 21 | Wants=network-online.target |
| 22 | |
| 23 | [Service] |
| 24 | Type=oneshot |
| 25 | # Same host-wide config the edge reads: CARLOS_HIBERNATE_* names the replica |
| 26 | # set, CARLOS_DEPLOYMENT_BUCKET/_DIR is where the verdict is published. |
| 27 | # Deliberately NOT /data/litestream.env — those credentials belong to the |
| 28 | # box-wide replication bucket, and borrowing them here would sign for the |
| 29 | # wrong store. |
| 30 | EnvironmentFile=-/etc/carlos/host.env |
| 31 | ExecStart=/opt/carlos/carlos ops hibernate-verify |
| 32 | # Disk, not the PrivateTmp tmpfs — see carlos-restore-verify.service's note |
| 33 | # for the measurements. This drill is where it mattered most: the flagship's |
| 34 | # largest hibernating tenant is 412M and the first live run peaked at 485.6M |
| 35 | # against a 512M ceiling. On tmpfs that gap was ~30M of tenant growth away |
| 36 | # from an OOM kill on the very databases the drill is there to vouch for; on |
| 37 | # disk the same overrun only slows it down. |
| 38 | CacheDirectory=carlos-verify |
| 39 | Environment=TMPDIR=%C/carlos-verify |
| 40 | User=carlos |
| 41 | Group=carlos |
| 42 | CapabilityBoundingSet= |
| 43 | NoNewPrivileges=yes |
| 44 | ProtectSystem=strict |
| 45 | # The registry is opened (read-only in effect, but SQLite wants the file and |
| 46 | # its directory writable to attach WAL) — the same grant carlos-edge.service |
| 47 | # holds, for a unit running as the user that already owns /data. |
| 48 | ReadWritePaths=/data |
| 49 | ProtectHome=yes |
| 50 | PrivateTmp=yes |
| 51 | PrivateDevices=yes |
| 52 | RestrictAddressFamilies=AF_INET AF_INET6 |
| 53 | MemoryDenyWriteExecute=yes |
| 54 | # One-at-a-time by construction — lease.VerifyReplica deletes each throwaway |
| 55 | # copy in a defer — so this needs to clear the largest single tenant, not the |
| 56 | # fleet. Same ceiling and the same WATCH note as the sibling unit. |
| 57 | MemoryMax=512M |
| 58 | |