Compare commits

...

6 Commits

Author SHA1 Message Date
Alexandre
be5e76e219 Merge pull request #2201 from alexbelgium/codex/fix-meilisearch-exit-error
Fix Meilisearch startup supervision
2025-11-15 20:39:31 +01:00
Alexandre
560a74ea0e Bump Monica addon version 2025-11-15 20:38:54 +01:00
Alexandre
ec058113c7 Fix Meilisearch startup supervision 2025-11-15 20:34:01 +01:00
github-actions
4c250651b0 GitHub bot: changelog 2025-11-15 16:10:17 +00:00
Alexandre
f4e9080832 Update config.yaml 2025-11-15 16:42:23 +01:00
Alexandre
d8eb2dfaca Refactor MQTT client initialization
https://github.com/alexbelgium/hassio-addons/issues/2199#issuecomment-3536598328
2025-11-15 16:42:12 +01:00
6 changed files with 75 additions and 21 deletions

View File

@@ -1,3 +1,5 @@
## 2025.11.06 (15-11-2025)
- Minor bugs fixed
## 2025.11.05 (15-11-2025)
- Added support for configuring extra environment variables via the `env_vars` add-on option alongside config.yaml. See https://github.com/alexbelgium/hassio-addons/wiki/Add-Environment-variables-to-your-Addon-2 for details.

View File

@@ -116,5 +116,5 @@ tmpfs: true
udev: true
url: https://github.com/alexbelgium/hassio-addons/tree/master/birdnet-pi
usb: true
version: 2025.11.05
version: 2025.11.06
video: true

View File

@@ -112,15 +112,17 @@ def automatic_mqtt_publish(file, detection, path):
mqttc.publish(mqtt_topic, json_bird, 1)
log.info("Posted to MQTT: ok")
# Create MQTT client using legacy callback API when available for
# compatibility with paho-mqtt >= 2.0
callback_api = getattr(mqtt, "CallbackAPIVersion", None)
if callback_api is not None:
mqttc = mqtt.Client("birdnet_mqtt", callback_api_version=callback_api.VERSION1)
# paho-mqtt >= 2.0: first argument is callback_api_version
mqttc = mqtt.Client(callback_api.VERSION1, client_id="birdnet_mqtt")
else:
mqttc = mqtt.Client("birdnet_mqtt")
# paho-mqtt < 2.0: old signature, first argument is client_id
mqttc = mqtt.Client(client_id="birdnet_mqtt")
mqttc.username_pw_set(mqtt_user, mqtt_pass)
mqttc.on_connect = on_connect

View File

@@ -1,3 +1,5 @@
## v5.0_beta5-4 (15-11-2025)
- Increment version for rebuilt add-on
## v5.0_beta5-3 (15-11-2025)
- Minor bugs fixed
## v5.0_beta6 (06-01-2025)

View File

@@ -107,5 +107,5 @@ services:
- mysql:want
slug: monica
url: https://github.com/alexbelgium/hassio-addons/tree/master/monica
version: v5.0_beta5-3
version: v5.0_beta5-4
webui: "[PROTO:ssl]://[HOST]:[PORT:80]"

View File

@@ -152,6 +152,52 @@ if [[ "${MEILISEARCH_LOCAL}" == true ]]; then
S6_SUPERVISED_DIR="/var/run/s6/services"
fi
S6_SVSCANCTL_BIN="$(command -v s6-svscanctl || true)"
if [ -z "${S6_SVSCANCTL_BIN}" ] && [ -x /command/s6-svscanctl ]; then
S6_SVSCANCTL_BIN="/command/s6-svscanctl"
fi
meilisearch_fail() {
local message="$1"
local exit_code="${2:-1}"
bashio::log.error "${message}"
if [ -n "${S6_SVSCANCTL_BIN}" ]; then
if ! "${S6_SVSCANCTL_BIN}" -t "${S6_SUPERVISED_DIR}" 2>/dev/null; then
bashio::log.error "Unable to signal s6-svscanctl to stop services"
fi
else
bashio::log.error "s6-svscanctl binary not found; unable to stop services gracefully"
fi
if [ "${exit_code}" -eq 0 ]; then
exit_code=1
fi
exit "${exit_code}"
}
meilisearch_ensure_running() {
if kill -0 "${MEILISEARCH_PID}" 2>/dev/null; then
return 0
fi
local exit_code=0
set +e
wait "${MEILISEARCH_PID}"
exit_code=$?
set -e
local wait_code="${exit_code}"
if [ "${exit_code}" -eq 0 ]; then
exit_code=1
fi
meilisearch_fail "Meilisearch exited unexpectedly (code ${wait_code}). Stopping add-on." "${exit_code}"
}
MEILISEARCH_CMD=(
env \
MEILI_ENV="${MEILISEARCH_ENVIRONMENT}" \
@@ -168,19 +214,20 @@ if [[ "${MEILISEARCH_LOCAL}" == true ]]; then
"${MEILISEARCH_CMD[@]}" &
MEILISEARCH_PID=$!
(
set +e
wait "${MEILISEARCH_PID}"
exit_code=$?
set -e
if [ "${exit_code}" -ne 0 ]; then
bashio::log.error "Meilisearch exited unexpectedly (code ${exit_code}). Stopping add-on."
s6-svscanctl -t "${S6_SUPERVISED_DIR}"
fi
) &
bashio::log.info "Waiting for Meilisearch TCP socket"
bashio::net.wait_for "${MEILISEARCH_ADDR%:*}" "${MEILISEARCH_ADDR#*:}"
for attempt in $(seq 1 30); do
if bash -c "cat < /dev/null > /dev/tcp/${MEILISEARCH_HOST}/${MEILISEARCH_PORT}" 2>/dev/null; then
break
fi
meilisearch_ensure_running
if [ "${attempt}" -eq 30 ]; then
meilisearch_fail "Meilisearch TCP socket did not become ready in time. Stopping add-on."
fi
sleep 1
done
bashio::log.info "Waiting for Meilisearch health endpoint"
MEILISEARCH_HEALTH_URL="${MEILISEARCH_URL%/}/health"
@@ -189,12 +236,13 @@ if [[ "${MEILISEARCH_LOCAL}" == true ]]; then
bashio::log.info "Meilisearch is ready"
break
fi
sleep 1
meilisearch_ensure_running
if [ "${attempt}" -eq 30 ]; then
bashio::log.error "Meilisearch did not become ready in time. Stopping add-on."
s6-svscanctl -t "${S6_SUPERVISED_DIR}"
exit 1
meilisearch_fail "Meilisearch did not become ready in time. Stopping add-on."
fi
sleep 1
done
else
bashio::log.info "Detected external Meilisearch endpoint (${MEILISEARCH_URL}); skipping bundled service startup"