#!/usr/bin/env python3 """redis6c.py — R-1096 6c on a test box after the catalog push: sync, then per app the dashboard's restart, and the Redis facts before/after (DBSIZE, INFO persistence, the container's Created + Cmd). Env SC, EV, TARGET; args: apps. `--no-restart` only reads (a box where CC presses nothing).""" import os, sys, time sys.path.insert(0, "/mnt/5_hdd/felhom.eu/git/app-catalog-felhom.eu/scripts") import box_walk as w # noqa: E402 EV = os.environ["EV"] LOG = open(os.path.join(EV, f"6c-{w.TARGET}.txt"), "a", buffering=1) _say = w.say def say(*a): _say(*a); LOG.write(time.strftime("%H:%M:%S ") + " ".join(str(x) for x in a) + "\n") w.say = say def facts(app): rc = f"{'paperless' if app == 'paperless-ngx' else app}-redis" out = w.guest(f"""echo "compose: $(grep -h 'redis-server' /opt/docker/stacks/{app}/docker-compose.yml /opt/docker/stacks/{app}/applied-compose.yml | tr -s ' ' | tr '\\n' '|')" echo "container: $(docker inspect -f '{{{{.Created}}}} {{{{json .Config.Cmd}}}}' {rc}) $(docker ps --filter name=^{rc}$ --format '{{{{.Status}}}}')" echo "dbsize: $(docker exec {rc} redis-cli DBSIZE) $(docker exec {rc} redis-cli INFO persistence | grep -E 'aof_enabled|rdb_last_bgsave_status' | tr -d '\\r' | tr '\\n' ' ')" echo "/data: $(docker exec {rc} ls /data | tr '\\n' ' ')" """) return out.strip() def main(): apps = [a for a in sys.argv[1:] if not a.startswith("--")] w.login() code, d = w.ctl("POST", "/api/sync") say(f"POST /api/sync -> {code} {str(d)[:200]}") time.sleep(5) for app in apps: say(f"== {app} before:\n{facts(app)}") if "--no-restart" in sys.argv: continue c, d = w.ctl("POST", f"/api/stacks/{app}/restart") say(f" POST /api/stacks/{app}/restart -> {c} {str(d)[:120]}") for _ in range(60): time.sleep(5) if w.stack(app).get("state") == "running": break time.sleep(15) st = w.stack(app) say(f"== {app} after (state={st.get('state')} hold={st.get('hold_reason')!r}):\n{facts(app)}") main()