From 374f4ade31d09b4dbbda67c9b29391282971fd7d Mon Sep 17 00:00:00 2001 From: noroot Date: Thu, 27 Aug 2026 17:24:41 +0200 Subject: [PATCH] fix: heal missing RULES_DIR in postinst on upgrade MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Discovered live: upgrading the test server to v0.2.0 crash-looped with "rules: read dir: open .: no such file or directory". Its /etc/deklarix/deklarix.env predates RULES_DIR entirely (created on first install, before that variable existed) — postinst never overwrites an existing env file, by design, so the variable was simply missing rather than set. main.go's relative default "rules" then resolved against WorkingDirectory=/var/lib/deklarix instead of the actual install path (/usr/share/deklarix/rules). postinst now appends RULES_DIR with its packaged default whenever it's absent, on both fresh installs and upgrades — never overwriting an existing value. Same healing pattern enconf uses for DB_SSLMODE. Verified: reinstalling over the broken config fixed it and the service came back up. Co-Authored-By: Claude Sonnet 5 --- packaging/DEBIAN/postinst | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/packaging/DEBIAN/postinst b/packaging/DEBIAN/postinst index 1499ada..268caed 100755 --- a/packaging/DEBIAN/postinst +++ b/packaging/DEBIAN/postinst @@ -42,6 +42,20 @@ case "$1" in chown "root:$SERVICE_USER" "$CONFIG_DIR/deklarix.env" fi + # ─── Healing: fehlende Variablen aus älteren Installationen ─── + # deklarix.env wird bei Upgrades nie überschrieben (Secrets/ + # Anpassungen bleiben erhalten) — Variablen, die erst nach einer + # Erstinstallation dazugekommen sind, fehlen dort sonst schlicht + # und lassen den Dienst mit einem für den Admin überraschenden + # Fehler abbrechen (z. B. RULES_DIR fehlt -> main.go sucht Regeln + # im falschen Verzeichnis, obwohl DATABASE_URL längst gesetzt + # war). Bekannte Variablen mit unkritischem Default werden hier + # ergänzt, falls sie fehlen — nie überschrieben, nur angehängt. + if [ -f "$CONFIG_DIR/deklarix.env" ]; then + grep -q '^RULES_DIR=' "$CONFIG_DIR/deklarix.env" || \ + echo "RULES_DIR=/usr/share/deklarix/rules" >> "$CONFIG_DIR/deklarix.env" + fi + systemctl daemon-reload 2>/dev/null || true systemctl enable deklarix.service >/dev/null 2>&1 || true