Files
app-catalog-felhom.eu/scripts/check-redis-persistence.py
admin 5d9450b066
gates / gates (push) Successful in 5s
Redis snapshots, not append-only, on five apps (R-1096); gate redis-persistence
romm, docmost, paperless-ngx, immich, nextcloud: redis-server --appendonly no (was yes); volumes kept. Proved on
scratch 9202 first: 100/100 keys through the switch and through the nightly volume dump + restore; a damaged AOF
refuses to start, a snapshot on a full disk keeps the old file. steps/ files unchanged (tested definitions,
09 6.4 part 5). New --fast gate check-redis-persistence.py with 9 decoy cases, red-proved.

Claude-Session: https://claude.ai/code/session_0159rPz1ZhFKsS53msqPYxtS
2026-10-17 09:22:37 +02:00

134 lines
5.2 KiB
Python

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""check-redis-persistence.py — no catalog Redis runs append-only (AOF); snapshots (RDB) only.
python3 scripts/check-redis-persistence.py # every template's docker-compose.yml
python3 scripts/check-redis-persistence.py --root DIR # another checkout (the decoy harness)
WHY (R-1096, 2026-10-17). An append-only file damaged in the MIDDLE — what the 2026-09-24 thin-pool fill left in
docmost's and romm's Redis (zero bytes near the end) — makes Redis refuse to start until a person runs
`redis-check-aof --fix`, and the app stays down. A snapshot (RDB) is written to a temp file and renamed only when
complete, so a full disk leaves the old snapshot intact (measured on 9202: the save fails, the old dump.rdb is
byte-identical, Redis starts again on it — felhom.eu audits/burndown-3-2026-10-17/P6/). The five apps were switched to
`--appendonly no` in one commit; this gate keeps a sixth from arriving with AOF.
WHAT IS JUDGED: every service of templates/<app>/docker-compose.yml whose image is redis or valkey; its `command:`
(string, flow list or block list) must not turn AOF on (`--appendonly yes` / `appendonly yes`). A service with no
command runs the image's default, which is RDB. NOT judged, on purpose: `steps/<key>.yml` — a ladder step is its own
TESTED definition and a box climbing the ladder runs it unchanged (`09` §6.4 part 5); a box reaches RDB at the head.
LIMIT, stated: a mounted redis.conf is not read (no catalog template mounts one today).
STANDARD LIBRARY ONLY (the CI runner has no PyYAML); comments never count.
Exit 0 clean · 1 a template runs AOF · 3 nothing to judge.
"""
import io
import os
import re
import sys
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
REDIS_IMAGES = ("redis", "valkey")
def strip_comment(line):
out, q = [], None
for c in line:
if q:
if c == q:
q = None
elif c in "'\"":
q = c
elif c == "#":
break
out.append(c)
return "".join(out).rstrip()
def is_redis(image):
image = image.strip().strip("'\"").split("@", 1)[0]
last = image.rsplit("/", 1)[-1].split(":", 1)[0]
return last in REDIS_IMAGES
def services(path):
"""{service: (image, command text)} — the command's string, flow list or block list joined by spaces."""
out, cur, in_svcs, in_cmd = {}, None, False, False
with io.open(path, encoding="utf-8") as f:
for raw in f:
line = strip_comment(raw.rstrip("\n"))
if not line.strip():
continue
ind = len(line) - len(line.lstrip(" "))
if ind == 0:
in_svcs, cur = line.startswith("services:"), None
continue
if not in_svcs:
continue
if ind == 2 and line.strip().endswith(":"):
cur = line.strip()[:-1]
out[cur] = ["", ""]
in_cmd = False
continue
if cur is None:
continue
if ind == 4:
in_cmd = False
m = re.match(r"^\s{4}image:\s*(\S+)", line)
if m:
out[cur][0] = m.group(1)
m = re.match(r"^\s{4}command:\s*(.*)$", line)
if m:
out[cur][1] = m.group(1)
in_cmd = m.group(1).strip() == ""
continue
if in_cmd and ind >= 6:
m = re.match(r"^\s*-\s*(.+)$", line)
if m:
out[cur][1] += " " + m.group(1)
return out
def runs_aof(command):
toks = re.findall(r"[^\s\[\],\"']+", command)
for i, t in enumerate(toks[:-1]):
if t.lstrip("-") == "appendonly" and toks[i + 1].lower() == "yes":
return True
return False
def main(argv):
root = ROOT
if "--root" in argv:
root = argv[argv.index("--root") + 1]
for a in argv:
if a.startswith("--root="):
root = a.split("=", 1)[1]
tdir = os.path.join(root, "templates")
if not os.path.isdir(tdir):
print("check-redis-persistence: no templates/ under %s — nothing to judge (a failure, never a pass)" % root)
return 3
bad, judged = [], 0
for app in sorted(os.listdir(tdir)):
p = os.path.join(tdir, app, "docker-compose.yml")
if not os.path.isfile(p):
continue
for svc, (image, cmd) in services(p).items():
if not is_redis(image):
continue
judged += 1
if runs_aof(cmd):
bad.append("%s/docker-compose.yml: service %s (%s) runs append-only — `command: %s`. Use "
"`--appendonly no` (snapshots): a damaged AOF keeps Redis down until a person repairs it "
"(R-1096)" % (app, svc, image, cmd.strip()))
if bad:
print("check-redis-persistence: FAIL — %d Redis service(s) run append-only:" % len(bad))
for b in bad:
print(" - " + b)
return 1
print("check-redis-persistence gate OK — %d Redis service(s), none append-only" % judged)
return 0
if __name__ == "__main__":
sys.exit(main(sys.argv[1:]))