From d826505bdbe528153e7ce1a2353abf33527b71d4 Mon Sep 17 00:00:00 2001 From: Thomas Stallinger Date: Wed, 2 Sep 2026 07:24:15 +0200 Subject: [PATCH] agent/bootstrap: Debug-Modus automatisch beim allerersten Bootstrap aktivieren Vor dem UPDATE geprueft, ob agent_secret_issued_at noch NIE gesetzt war - nur dann (echte Neuinstallation, nicht ein spaeterer Self-Heal-Re- Bootstrap bei 401 auf checkin) wird debug_mode_until gleich mit auf jetzt+DEBUG_MODE_DURATION_HOURS gesetzt. Nutzer-Wunsch (02.09.2026): kurz nach dem ersten Boot des fertig installierten Systems soll ein frisch zugewiesenes Merkmal ohne stundenlange Wartezeit (normales Poll-Intervall: 6 Stunden) ankommen - der Debug-Modus (60s-Intervall) ist dafuer schon vorhanden, sprang bisher aber nie automatisch an. --- app.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/app.py b/app.py index d9d0f39..b9c5d2a 100644 --- a/app.py +++ b/app.py @@ -2694,6 +2694,23 @@ def agent_bootstrap(payload: AgentBootstrapRequest): with get_database_connection() as conn: with conn.cursor() as cur: + # Vor dem Update geprueft: war agent_secret_issued_at NOCH NIE + # gesetzt? Das unterscheidet den ALLERERSTEN Bootstrap (echte + # Neuinstallation, siehe postinstall.sh) von einem spaeteren + # Self-Heal-Re-Bootstrap (401 auf checkin, agent.py) - nur beim + # allerersten Mal wird gleich anschliessend automatisch der + # Debug-Modus aktiviert (Nutzer-Wunsch 02.09.2026: kurz nach dem + # ersten Boot des fertig installierten Systems soll ein frisch + # zugewiesenes Merkmal ohne stundenlange Wartezeit ankommen, + # ohne dass der Debug-Modus jedesmal bei jedem Re-Bootstrap + # erneut anspringt). + cur.execute( + "SELECT agent_secret_issued_at FROM devices WHERE id = %s", + (payload.device_id,), + ) + vorher = cur.fetchone() + ist_erstinstallation = vorher is not None and vorher[0] is None + cur.execute( """ UPDATE devices @@ -2715,6 +2732,14 @@ def agent_bootstrap(payload: AgentBootstrapRequest): (payload.device_id,), ) existing = cur.fetchone() + elif ist_erstinstallation: + cur.execute( + "UPDATE devices SET debug_mode_until = %s WHERE id = %s", + ( + datetime.now(timezone.utc) + timedelta(hours=DEBUG_MODE_DURATION_HOURS), + payload.device_id, + ), + ) if updated is None: if existing is not None and existing[0] is not None: