From ba3e172ddab6b115a25ec6f5a4afa7ce74f52225 Mon Sep 17 00:00:00 2001 From: David Gwilliam Date: Thu, 9 Jul 2026 18:56:36 -0700 Subject: [PATCH] fix: power outage auto-recovery improvements Mosquitto: - Change restart: always (was unless-stopped) to survive daemon restarts - Add healthcheck (pub/sub ping) for depends_on conditions - All downstream services use condition: service_healthy Party-lock: - Add MQTT connection retry loop (was crashing on DNS race after restart) Zigbee2mqtt: - Add entrypoint wrapper that auto-applies BLZ bridge patch at startup - Bridge patch no longer needs manual 'just z2m-patch-bridge' after image pulls Mopidy: - Add python3-gi + python3-gi-cairo via apt (fixes 'No module named gi') - Set PYTHONPATH to expose system gi module to Python 3.12 --- infra/compose.yaml | 18 ++++++++++++++---- infra/mopidy/Dockerfile | 10 +++++++++- infra/party-lock/party-lock.py | 8 +++++++- infra/zigbee2mqtt/scripts/entrypoint.sh | 6 ++++++ 4 files changed, 36 insertions(+), 6 deletions(-) create mode 100755 infra/zigbee2mqtt/scripts/entrypoint.sh diff --git a/infra/compose.yaml b/infra/compose.yaml index 9021949..e0cb182 100644 --- a/infra/compose.yaml +++ b/infra/compose.yaml @@ -2,7 +2,7 @@ services: mosquitto: image: eclipse-mosquitto:latest container_name: mosquitto - restart: unless-stopped + restart: always user: "1883:1883" ports: - "1883:1883" @@ -10,6 +10,12 @@ services: - ./mosquitto/config:/mosquitto/config - ./mosquitto/data:/mosquitto/data - ./mosquitto/log:/mosquitto/log + healthcheck: + test: ["CMD", "sh", "-c", "timeout 3 mosquitto_sub -p 1883 -t healthcheck -C 1 --quiet & sleep 0.5 && mosquitto_pub -p 1883 -t healthcheck -m ok -r; wait"] + interval: 10s + timeout: 5s + retries: 3 + start_period: 15s zigbee2mqtt: image: ghcr.io/pine64/zigbee2mqtt:latest-dev # BLZ fork, NOT koenkk @@ -23,6 +29,7 @@ services: - ./zigbee2mqtt:/app/data devices: - /dev/ttyUSB0:/dev/ttyUSB0 + entrypoint: ["/app/data/scripts/entrypoint.sh"] environment: TZ: America/Los_Angeles @@ -43,7 +50,8 @@ services: container_name: nodered restart: unless-stopped depends_on: - - mosquitto + mosquitto: + condition: service_healthy user: "1000:1000" ports: - "1880:1880" @@ -65,7 +73,8 @@ services: container_name: doorbell-listener restart: unless-stopped depends_on: - - mosquitto + mosquitto: + condition: service_healthy volumes: - ./doorbell-listener/state:/data/doorbell-listener environment: @@ -146,7 +155,8 @@ services: container_name: party-lock restart: unless-stopped depends_on: - - mosquitto + mosquitto: + condition: service_healthy volumes: - ./mosquitto/config:/mosquitto/config - /var/run/docker.sock:/var/run/docker.sock diff --git a/infra/mopidy/Dockerfile b/infra/mopidy/Dockerfile index b5cdf41..1621c7a 100644 --- a/infra/mopidy/Dockerfile +++ b/infra/mopidy/Dockerfile @@ -14,12 +14,20 @@ RUN apt-get update \ libpango-1.0-0 \ libpangoft2-1.0-0 \ libgirepository-1.0-1 \ - libgirepository1.0-dev \ gir1.2-glib-2.0 \ gir1.2-gstreamer-1.0 \ gir1.2-gst-plugins-base-1.0 \ && rm -rf /var/lib/apt/lists/* +RUN apt-get update \ + && apt-get install -y --no-install-recommends \ + python3-gi \ + python3-gi-cairo \ + && rm -rf /var/lib/apt/lists/* + +# Expose the system Python's gi module to Python 3.12 (/usr/local). +ENV PYTHONPATH=/usr/lib/python3/dist-packages:${PYTHONPATH} + RUN pip install --no-cache-dir \ "setuptools<80" \ Mopidy==3.4.2 \ diff --git a/infra/party-lock/party-lock.py b/infra/party-lock/party-lock.py index dfc6f62..9bf23b5 100644 --- a/infra/party-lock/party-lock.py +++ b/infra/party-lock/party-lock.py @@ -51,7 +51,13 @@ def main(): rebuild_acl() client = mqtt.Client(mqtt.CallbackAPIVersion.VERSION2) client.on_message = on_message - client.connect(MQTT_HOST, MQTT_PORT, 60) + while True: + try: + client.connect(MQTT_HOST, MQTT_PORT, 60) + break + except Exception as e: + print(f"mqtt connect failed: {e}; retrying in 5s", flush=True) + time.sleep(5) client.subscribe("party-lock/set", qos=1) client.loop_forever() diff --git a/infra/zigbee2mqtt/scripts/entrypoint.sh b/infra/zigbee2mqtt/scripts/entrypoint.sh new file mode 100755 index 0000000..912fdc7 --- /dev/null +++ b/infra/zigbee2mqtt/scripts/entrypoint.sh @@ -0,0 +1,6 @@ +#!/bin/sh +set -e + +node /app/data/scripts/blz-bridge-patch.js + +exec docker-entrypoint.sh "$@"