diff --git a/birdnet-pi/CHANGELOG.md b/birdnet-pi/CHANGELOG.md index 2932efbb0f..0e7a0db2ff 100644 --- a/birdnet-pi/CHANGELOG.md +++ b/birdnet-pi/CHANGELOG.md @@ -1,3 +1,7 @@ +## 2026.08.02 (02-08-2026) +- Fix: ingress returned "502 Bad Gateway" because Caddy never listened on :8082. `91-nginx_ingress.sh` hooked the ingress site into `update_caddyfile.sh` with a sed anchored on `sudo caddy fmt --overwrite`, but 2026.07.10-1 strips `sudo` from every BirdNET-Pi script at build time, so the anchor stopped matching. `update_caddyfile.sh` then rewrote the Caddyfile from scratch just before Caddy started, dropping the ingress site +- Fix: `caddy_ingress.sh` no longer appends a second `:8082` block when it runs twice (a duplicate site address makes Caddy refuse to start) +- Fix: `02-caddy.sh` re-adds the ingress site if it is missing from the Caddyfile just before starting Caddy ## 2026.07.22 (22-07-2026) - Fix: health-check the WebUI port (8081) instead of port 80, so the standalone Docker container no longer reports "unhealthy" when ssl=false - Fix: health-check now probes https when ssl is enabled, and no longer silently reports "healthy" regardless of the actual result (the previous check's `&>` redirection is a bash-ism that dash, the image's /bin/sh, parses as background + no-op, discarding curl's exit status) diff --git a/birdnet-pi/config.yaml b/birdnet-pi/config.yaml index 7b86eb67f0..c384100e7a 100644 --- a/birdnet-pi/config.yaml +++ b/birdnet-pi/config.yaml @@ -116,5 +116,5 @@ tmpfs: true udev: true url: https://github.com/alexbelgium/hassio-addons/tree/master/birdnet-pi usb: true -version: 2026.07.22 +version: 2026.08.02 video: true diff --git a/birdnet-pi/rootfs/custom-services.d/02-caddy.sh b/birdnet-pi/rootfs/custom-services.d/02-caddy.sh index 6162c5f49e..2d93838010 100755 --- a/birdnet-pi/rootfs/custom-services.d/02-caddy.sh +++ b/birdnet-pi/rootfs/custom-services.d/02-caddy.sh @@ -25,5 +25,24 @@ export TZ="${TZ_VALUE:-Etc/UTC}" # Update caddyfile with password "$HOME"/BirdNET-Pi/scripts/update_caddyfile.sh &> /dev/null || true +# update_caddyfile.sh rewrites the Caddyfile from scratch. 91-nginx_ingress.sh +# hooks the ingress site back into it, but if that hook ever fails to apply, +# caddy would start without a :8082 listener and ingress would answer 502. +# 91-nginx_ingress.sh writes /ingress_url when ingress is on and removes it when +# it is off, so this is a no-op in standalone mode. +# Require the Caddyfile to exist: if it is missing something went badly wrong +# earlier, and caddy failing on a missing config is easier to diagnose than an +# ingress-only Caddyfile conjured up here. +if [[ -f /ingress_url ]] && [[ -f /etc/caddy/Caddyfile ]] \ + && ! grep -qE '^[[:space:]]*:8082[[:space:]]*\{' /etc/caddy/Caddyfile 2> /dev/null; then + echo "Ingress site missing from the Caddyfile, re-adding it" + if ! /helpers/caddy_ingress.sh; then + # Start caddy anyway: ingress stays broken, but direct access on 8081 + # keeps working. Exiting here would only make s6 restart this service in + # a loop and take the WebUI down completely. + echo "Failed to re-add the ingress site, the ingress panel will return 502" >&2 + fi +fi + echo "Starting service: caddy" exec /usr/bin/caddy run --config /etc/caddy/Caddyfile diff --git a/birdnet-pi/rootfs/etc/cont-init.d/91-nginx_ingress.sh b/birdnet-pi/rootfs/etc/cont-init.d/91-nginx_ingress.sh index 8cb144c4b9..286e239f5d 100755 --- a/birdnet-pi/rootfs/etc/cont-init.d/91-nginx_ingress.sh +++ b/birdnet-pi/rootfs/etc/cont-init.d/91-nginx_ingress.sh @@ -26,6 +26,10 @@ ingress_entry=$(bashio::addon.ingress_entry) if [[ "$ingress_entry" != "/api"* ]]; then bashio::log.info "Ingress entry is not set, exiting configuration." sed -i "1a sleep infinity" /custom-services.d/02-nginx.sh + # This script re-runs from /etc/scripts-init on an add-on restart, so drop + # any marker left by an earlier run: it is what 02-caddy.sh reads to decide + # whether the ingress site belongs in the Caddyfile. + rm -f /ingress_url exit 0 fi @@ -68,9 +72,23 @@ sed -i "s|localhost|localhost:8082|g" "$HOME/BirdNET-Pi/scripts/utils/notificati # Update the Caddyfile if update script exists caddy_update_script="$HOME/BirdNET-Pi/scripts/update_caddyfile.sh" -if [ -f "$caddy_update_script" ]; then - sed -i "/sudo caddy fmt --overwrite/i /helpers/caddy_ingress.sh" "$caddy_update_script" -else +if [ ! -f "$caddy_update_script" ]; then bashio::log.error "Caddy update script not found: $caddy_update_script" exit 1 fi + +# update_caddyfile.sh rewrites /etc/caddy/Caddyfile from scratch, which drops +# the ingress site added just above. 02-caddy.sh runs it right before starting +# caddy, so the hook below has to re-add the site from inside that script, just +# before it formats and reloads the config. +# The anchor must not require "sudo": the Dockerfile strips it from every +# BirdNET-Pi script at build time, so the shipped line is "caddy fmt --overwrite". +if ! grep -qF "/helpers/caddy_ingress.sh" "$caddy_update_script"; then + sed -i -E "/^[[:space:]]*(sudo[[:space:]]+)?caddy[[:space:]]+fmt[[:space:]]+--overwrite/i /helpers/caddy_ingress.sh" "$caddy_update_script" +fi + +# sed is silent when the anchor is missing; make sure the hook is really there +if ! grep -qF "/helpers/caddy_ingress.sh" "$caddy_update_script"; then + bashio::log.warning "Could not anchor the ingress site in $caddy_update_script, appending it instead" + printf '\n/helpers/caddy_ingress.sh\n' >> "$caddy_update_script" +fi diff --git a/birdnet-pi/rootfs/helpers/caddy_ingress.sh b/birdnet-pi/rootfs/helpers/caddy_ingress.sh index 8b2db827e1..c9d845e6aa 100755 --- a/birdnet-pi/rootfs/helpers/caddy_ingress.sh +++ b/birdnet-pi/rootfs/helpers/caddy_ingress.sh @@ -6,6 +6,13 @@ set +u # shellcheck disable=SC1091 source /etc/birdnet/birdnet.conf +# Nothing to do if the ingress site is already there. This script runs both from +# cont-init and from update_caddyfile.sh, and a duplicate ":8082" site address +# makes caddy refuse to start. +if grep -qE '^[[:space:]]*:8082[[:space:]]*\{' /etc/caddy/Caddyfile 2> /dev/null; then + exit 0 +fi + # Create ingress configuration for Caddyfile cat << EOF >> /etc/caddy/Caddyfile :8082 {