Zoo

← back to the zoo

24. The server can be replaced

The whole platform can be rebuilt on a fresh machine from the tools repo, one bundle of secrets, and one backup.

Nothing refers to the machine: a rehearsal restores everything onto a scratch box and checks every app answers. Its verdict reaches each app in RC_FACTS/backup.json.

This is the code serving the zoo right now: read from disk for this request, from commit 0c1c124a02 (live). The zoo's own self-check fetches this page and compares it byte for byte with the file it runs.

exhibits/24-replaceable-server.php sha256 9bc4260d0ccd · raw

1<?php
2// Exhibit 24. `rc rehearse` rebuilds the whole platform on a scratch machine from the tools repo,
3// the secrets bundle and the newest backup, and records the verdict. Root copies it into every
4// app's RC_FACTS/backup.json (rehearsal, rehearsal_last_pass).
5return [
6    "n" => 24, "wing" => "Operations",
7    "title" => "The server can be replaced",
8    "promise" => "The whole platform can be rebuilt on a fresh machine from the tools repo, one bundle of secrets, and one backup.",
9    "block" => "Nothing refers to the machine: a rehearsal restores everything onto a scratch box and checks every app answers. Its verdict reaches each app in RC_FACTS/backup.json.",
10    "show" => function (?array $me): string {
11        $b = fact("backup.json") ?? [];
12        $p = $b["rehearsal_last_pass"] ?? null; $last = $b["rehearsal"] ?? null;
13        if (!$last) return '<p class="muted">No rehearsal has been recorded yet.</p>';
14        return "<p>Last rehearsal " . ago(strtotime($last["at"])) . ": <b>" . (($last["result"] ?? "") === "pass" ? "everything came back" : "it failed") . "</b>."
15             . ($p ? " Last one that passed: " . ago(strtotime($p["at"])) . "." : "") . "</p>";
16    },
17    "check" => function (): array {
18        $p = fact("backup.json")["rehearsal_last_pass"] ?? null;
19        if (!$p) return [false, "no rehearsal has passed yet"];
20        $days = intdiv(time() - strtotime($p["at"]), 86400);
21        // Green within 14 days, amber (a warning, not an alarm) up to 90, red after. The Mac runs it weekly (tools/dev/rehearse-weekly.sh).
22        if ($days > 90) return [false, "the last passing rehearsal was $days days ago"];
23        if ($days > 14) return [true, "the last rehearsal that passed was $days days ago: due", ["amber" => true]];
24        return [true, "the last rehearsal that passed was $days day(s) ago"];
25    },
26];