diff --git a/deploy/federated/apply-updater-fix.py b/deploy/federated/apply-updater-fix.py new file mode 100755 index 0000000..5581fe0 --- /dev/null +++ b/deploy/federated/apply-updater-fix.py @@ -0,0 +1,40 @@ +#!/usr/bin/env python3 +"""One-shot patch for /federated/lib/functions.sh (Core suite repo). + +1) Register superbrain in EXTRA_APPS so /federated/bin/start can dispatch it. + Root cause of the 2026-11-03 outage: `bin/start superbrain` fell through + to usage/exit 2 because superbrain was absent from SERVICES, and + upgrade_app ignored the exit status and printed "Done upgrading" over a + dead stack (traefik then answered 404 for the whole host). +2) In upgrade_app, never report success over a stack that failed to start: + check the start exit status AND that the primary container is running + afterwards; alert via send_matrix_alert like the snapshot-failure path. +""" +import sys + +P = "/federated/lib/functions.sh" +s = open(P).read() + +old_apps = '"mcpserver" "erpnext" "hermes")' +new_apps = '"mcpserver" "erpnext" "hermes" "superbrain")' +if s.count(old_apps) != 1: + sys.exit("EXTRA_APPS anchor not found exactly once") +s = s.replace(old_apps, new_apps) + +old_start = """ else + /federated/bin/start $APP + if [ -x "/federated/services/${APP}/upgrade/post" ]; then""" +new_start = """ else + /federated/bin/start $APP + if [ $? -ne 0 ] && [ "$(docker container inspect -f '{{.State.Running}}' $APP 2>/dev/null)" != "true" ]; then + send_matrix_alert "$DOMAIN ($EXTERNALIP): upgrade of $APP to $VERSION finished but the app did not come back up - investigate now, the service is likely DOWN" + echo -ne "ERROR: start $APP failed during upgrade - app may be DOWN, not reporting success.\\n" + return 1 + fi + if [ -x "/federated/services/${APP}/upgrade/post" ]; then""" +if s.count(old_start) != 1: + sys.exit("start-call anchor not found exactly once") +s = s.replace(old_start, new_start) + +open(P, "w").write(s) +print("functions.sh patched OK")