Files
felhom.eu/documentation/audits/night-2026-09-26/tools/teardown.py
T

30 lines
2.1 KiB
Python

#!/usr/bin/env python3
"""Night 2026-09-25 Part G (adapted from 09-24), the MACHINE layer on 9202: tonight's apps removed THROUGH THE PRODUCT, leftovers read by name,
the backup window put back to 02:30 through the product's own form. Apps present before tonight stay:
privatebin, paperless-ngx, filebrowser (gokapi was removed in chaos round 5 — R-644's disposition)."""
import json, sys, time
sys.path.insert(0, ".")
import walk as w
w.login()
apps = ["wishlist", "navidrome", "romm", "vikunja", "n8n", "mealie"]
q = lambda: w.guest("for p in " + " ".join(apps) + "; do echo \"$p containers=$(docker ps -aq --filter label=com.docker.compose.project=$p | wc -l) volumes=$(docker volume ls -q | grep -c ^${p}_) undo_copies=$(docker volume ls -q --filter label=felhom.undo-copy-of=$p | wc -l)\"; done; docker ps --format '{{.Names}}' | sort | tr '\\n' ' '")
before = q(); w.say("before:\n" + before)
res = {}
for a in apps:
st = w.stack(a)
if not st.get("deployed"):
res[a] = "not deployed"; continue
res[a] = w.remove(a)
after = q(); w.say("after the product's removes:\n" + after)
dirs = w.guest("ls -d /mnt/felhom-drives/scratch_hdd/userdata/*/ 2>/dev/null; ls /mnt/sys_drive/felhom-data/backups/secondary/ 2>/dev/null; ls -d /mnt/felhom-drives/scratch_hdd/userdata/*/backups/secondary/* 2>/dev/null")
w.say("drive dirs left (read by name):\n" + dirs)
sess = open(f"{w.SC}/sess{__import__('os').getpid()}.txt").read().strip()
csrf = open(f"{w.SC}/csrf{__import__('os').getpid()}.txt").read().strip()
r = w.sh(["curl", "-sk", "-o", "/dev/null", "-w", "%{http_code}", "-H", w.HOSTHDR, "-H", f"Cookie: {sess}", "-X", "POST",
"--data-urlencode", f"_csrf={csrf}", "--data-urlencode", "window_start=02:30", f"{w.BASE}/backups/window"])
time.sleep(2)
win = w.guest("docker logs --since 1m felhom-controller 2>&1 | grep -E 'rescheduled|window set' | tail -4")
w.say(f"backup window -> 02:30: {r.stdout}\n{win}")
json.dump({"before": before, "remove": res, "after": after, "dirs": dirs, "window": win}, open("../G/G2-machine-removes.json", "w"), indent=2)
open("../G/G2-machine-removes.log", "w").write("\n".join(w.LOG) + "\n")