From 5e94de0e5953e3348bd28309e66aaef560364c01 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 5 Jul 2026 19:59:27 +0000 Subject: [PATCH] fix(birdnet-go): persist sqlite database across restarts Upstream's shipped default config.yaml explicitly sets output.sqlite.path to the relative "birdnet.db", so the missing-only ("//=") seeding of that key never fired. A relative path resolves against the app's ephemeral container working directory instead of the persistent /config volume, so the database was silently recreated empty on every restart. Rewrite any relative output.sqlite.path to live under /config on startup, leaving already-absolute (user-customized) paths untouched. Fixes https://github.com/tphakala/birdnet-go/discussions/3774 Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_01KHJ4o22cdcgdNtb81tBTPJ --- birdnet-go-dev/CHANGELOG.md | 3 +++ birdnet-go-dev/config.yaml | 2 +- .../rootfs/etc/cont-init.d/01-structure.sh | 14 ++++++++++++++ birdnet-go/CHANGELOG.md | 1 + birdnet-go/config.yaml | 2 +- birdnet-go/rootfs/etc/cont-init.d/01-structure.sh | 14 ++++++++++++++ 6 files changed, 34 insertions(+), 2 deletions(-) diff --git a/birdnet-go-dev/CHANGELOG.md b/birdnet-go-dev/CHANGELOG.md index 1c1b546b38..533ef56f81 100644 --- a/birdnet-go-dev/CHANGELOG.md +++ b/birdnet-go-dev/CHANGELOG.md @@ -1,3 +1,6 @@ +## source-20260705-2 (05-07-2026) +- Fix detections/database not persisting across restarts on a fresh install: upstream's default `config.yaml` ships `output.sqlite.path: birdnet.db` (relative) explicitly, so the missing-only (`//=`) seeding introduced previously never rewrote it to an absolute path. A relative path resolves against the app's ephemeral working directory, so the database was silently recreated empty on every restart. Any relative `output.sqlite.path` is now rewritten to live under the persistent `/config` on startup; values already set to an absolute path are left untouched. (https://github.com/tphakala/birdnet-go/discussions/3774) + ## source-20260705 (05-07-2026) - Minor bugs fixed ## source-2026070 (05-07-2026) diff --git a/birdnet-go-dev/config.yaml b/birdnet-go-dev/config.yaml index 0b2b6d25ec..5e402c3dea 100644 --- a/birdnet-go-dev/config.yaml +++ b/birdnet-go-dev/config.yaml @@ -127,5 +127,5 @@ slug: birdnet-go-dev udev: true url: https://github.com/alexbelgium/hassio-addons usb: true -version: "source-20260705" +version: "source-20260705-2" video: true diff --git a/birdnet-go-dev/rootfs/etc/cont-init.d/01-structure.sh b/birdnet-go-dev/rootfs/etc/cont-init.d/01-structure.sh index e8b37d980e..c554095a10 100755 --- a/birdnet-go-dev/rootfs/etc/cont-init.d/01-structure.sh +++ b/birdnet-go-dev/rootfs/etc/cont-init.d/01-structure.sh @@ -139,6 +139,20 @@ fi # survive container restarts. bashio::log.info "Seeding default configuration values (only if missing)" +# Upstream's shipped default config.yaml explicitly sets output.sqlite.path +# to the relative "birdnet.db", so the "//=" below (default-if-missing) +# never fires for it. A relative path resolves against the app's working +# directory, which lives in the ephemeral container filesystem rather than +# a persistent volume, so the database is silently recreated empty on every +# restart. Rewrite any relative sqlite path to live under the persistent +# /config so detections survive reboots. +CURRENT_SQLITE_PATH="$(yq -r '.output.sqlite.path // ""' "$CONFIG_LOCATION")" +if [[ -n "$CURRENT_SQLITE_PATH" && "$CURRENT_SQLITE_PATH" != /* ]]; then + validate_safe_path "$CURRENT_SQLITE_PATH" + bashio::log.warning "output.sqlite.path ('$CURRENT_SQLITE_PATH') is relative and would not persist across restarts; rewriting to /config/$CURRENT_SQLITE_PATH" + yq -i -y ".output.sqlite.path = \"/config/${CURRENT_SQLITE_PATH}\"" "$CONFIG_LOCATION" +fi + yq -i -y '.output.sqlite.path //= "/config/birdnet.db"' "$CONFIG_LOCATION" #################### diff --git a/birdnet-go/CHANGELOG.md b/birdnet-go/CHANGELOG.md index e6c93a99cc..d0e83cdfcf 100644 --- a/birdnet-go/CHANGELOG.md +++ b/birdnet-go/CHANGELOG.md @@ -1,3 +1,4 @@ + - Fix detections/database not persisting across restarts on a fresh install: upstream's default `config.yaml` ships `output.sqlite.path: birdnet.db` (relative) explicitly, so the missing-only (`//=`) seeding introduced previously never rewrote it to an absolute path. A relative path resolves against the app's ephemeral working directory, so the database was silently recreated empty on every restart. Any relative `output.sqlite.path` is now rewritten to live under the persistent `/config` on startup; values already set to an absolute path are left untouched. (https://github.com/tphakala/birdnet-go/discussions/3774) - MQTT auto-config now also enables BirdNET-Go's native Home Assistant MQTT auto-discovery: detection sensors appear in Home Assistant automatically with no manual YAML (existing UI/config.yaml edits are preserved) - MQTT auto-config seeds `realtime.mqtt.retain: true` (only when unset) so sensor states survive Home Assistant restarts - Added supervisor watchdog (tcp://[HOST]:[PORT:8080]) so the add-on is automatically restarted if BirdNET-Go stops responding diff --git a/birdnet-go/config.yaml b/birdnet-go/config.yaml index 7d4d8dbef3..7799a3bfe1 100644 --- a/birdnet-go/config.yaml +++ b/birdnet-go/config.yaml @@ -128,4 +128,4 @@ slug: birdnet-go udev: true url: https://github.com/alexbelgium/hassio-addons/tree/master/birdnet-go usb: true -version: "nightly-20260615" +version: "nightly-20260615-2" diff --git a/birdnet-go/rootfs/etc/cont-init.d/01-structure.sh b/birdnet-go/rootfs/etc/cont-init.d/01-structure.sh index 5b5d49e310..65b44a633b 100755 --- a/birdnet-go/rootfs/etc/cont-init.d/01-structure.sh +++ b/birdnet-go/rootfs/etc/cont-init.d/01-structure.sh @@ -135,6 +135,20 @@ fi # survive container restarts. bashio::log.info "Seeding default configuration values (only if missing)" +# Upstream's shipped default config.yaml explicitly sets output.sqlite.path +# to the relative "birdnet.db", so the "//=" below (default-if-missing) +# never fires for it. A relative path resolves against the app's working +# directory, which lives in the ephemeral container filesystem rather than +# a persistent volume, so the database is silently recreated empty on every +# restart. Rewrite any relative sqlite path to live under the persistent +# /config so detections survive reboots. +CURRENT_SQLITE_PATH="$(yq -r '.output.sqlite.path // ""' "$CONFIG_LOCATION")" +if [[ -n "$CURRENT_SQLITE_PATH" && "$CURRENT_SQLITE_PATH" != /* ]]; then + validate_safe_path "$CURRENT_SQLITE_PATH" + bashio::log.warning "output.sqlite.path ('$CURRENT_SQLITE_PATH') is relative and would not persist across restarts; rewriting to /config/$CURRENT_SQLITE_PATH" + yq -i -y ".output.sqlite.path = \"/config/${CURRENT_SQLITE_PATH}\"" "$CONFIG_LOCATION" +fi + yq -i -y '.output.sqlite.path //= "/config/birdnet.db"' "$CONFIG_LOCATION" ####################