Merge pull request #2812 from alexbelgium/claude/birdnet-db-reboot-persistence-dzku9z

fix(birdnet-go): persist sqlite database across restarts
This commit is contained in:
Alexandre
2026-07-05 22:32:38 +02:00
committed by GitHub
6 changed files with 34 additions and 2 deletions

View File

@@ -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)

View File

@@ -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

View File

@@ -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"
####################

View File

@@ -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

View File

@@ -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"

View File

@@ -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"
####################