diff --git a/birdnet-go/CHANGELOG.md b/birdnet-go/CHANGELOG.md index 0b6751232b..ecbb5564ce 100644 --- a/birdnet-go/CHANGELOG.md +++ b/birdnet-go/CHANGELOG.md @@ -1,5 +1,5 @@ ## nightly-20260615-2 (2026-06-23) -- MariaDB auto-config: ensure the `birdnet` database exists before starting — birdnet-go does not create it automatically; if `CREATE DATABASE` fails due to insufficient privileges the script falls back to checking whether the database was pre-created manually, and exits with a clear instruction if it is missing +- MariaDB auto-config: resolve MariaDB hostname to IPv4 before connecting — on HAOS >=17.3 the Supervisor network gained IPv6 but the MariaDB addon only grants the service user from the IPv4 subnet, causing authentication failures and `CREATE DATABASE` errors; also add `--skip-ssl` to match the connection approach used by other addons - MariaDB auto-config: disabling `mariadb_auto_config` now reverts to SQLite only when `output.mysql.host` in config.yaml matches the HA MariaDB host (avoids clobbering manually-configured MySQL pointing at a different server) - Added `mariadb-client` to the addon packages so the `mysql` CLI used for database creation is available inside the container diff --git a/birdnet-go/rootfs/etc/cont-init.d/33-mariadb.sh b/birdnet-go/rootfs/etc/cont-init.d/33-mariadb.sh index d6cee19216..29d1e30772 100755 --- a/birdnet-go/rootfs/etc/cont-init.d/33-mariadb.sh +++ b/birdnet-go/rootfs/etc/cont-init.d/33-mariadb.sh @@ -68,30 +68,27 @@ bashio::log.blue "User: ${MYSQL_USER}" bashio::log.blue "Database: ${MYSQL_DATABASE}" bashio::log.green "---" -# Ensure the database exists. birdnet-go connects to an existing schema and -# does NOT create it automatically. MYSQL_PWD avoids password in process list. -# The HA MariaDB service user may lack global CREATE DATABASE privilege, so if -# CREATE DATABASE fails we fall back to checking whether the database already -# exists (pre-created manually or by a previous run with broader privileges). +# Resolve MariaDB hostname to IPv4: on HAOS >=17.3 the Supervisor network +# gained IPv6, but the MariaDB addon only grants its user from the IPv4 +# subnet. Fall back to the raw hostname if resolution fails. +MYSQL_HOST_RESOLVED="$(getent ahostsv4 "${MYSQL_HOST}" 2>/dev/null | awk '{print $1; exit}')" +MYSQL_HOST_RESOLVED="${MYSQL_HOST_RESOLVED:-${MYSQL_HOST}}" +if [ "${MYSQL_HOST_RESOLVED}" != "${MYSQL_HOST}" ]; then + bashio::log.blue "Resolved ${MYSQL_HOST} -> ${MYSQL_HOST_RESOLVED} (forcing IPv4)" +fi + +# Create the database — birdnet-go connects to an existing schema and does NOT +# create it automatically. MYSQL_PWD avoids exposing the password via the +# process command line. if ! MYSQL_PWD="${MYSQL_PASS}" mysql \ - --host="${MYSQL_HOST}" \ + --skip-ssl \ + --host="${MYSQL_HOST_RESOLVED}" \ --port="${MYSQL_PORT}" \ --user="${MYSQL_USER}" \ --connect-timeout=10 \ - -e "CREATE DATABASE IF NOT EXISTS \`${MYSQL_DATABASE}\` CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;" 2>/dev/null; then - bashio::log.warning "Could not CREATE DATABASE '${MYSQL_DATABASE}' (insufficient privileges?) — checking if it already exists" - if ! MYSQL_PWD="${MYSQL_PASS}" mysql \ - --host="${MYSQL_HOST}" \ - --port="${MYSQL_PORT}" \ - --user="${MYSQL_USER}" \ - --connect-timeout=10 \ - "${MYSQL_DATABASE}" \ - -e "SELECT 1;" >/dev/null 2>&1; then - bashio::log.error "Database '${MYSQL_DATABASE}' does not exist and could not be created." - bashio::log.error "Create it manually in MariaDB: CREATE DATABASE \`${MYSQL_DATABASE}\` CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;" - exit 1 - fi - bashio::log.yellow "Database '${MYSQL_DATABASE}' already exists — skipping creation" + -e "CREATE DATABASE IF NOT EXISTS \`${MYSQL_DATABASE}\` CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;"; then + bashio::log.error "Failed to create MariaDB database '${MYSQL_DATABASE}' — verify the MariaDB addon is running and the user has CREATE DATABASE privileges" + exit 1 fi bashio::log.blue "Database '${MYSQL_DATABASE}' is ready"