mirror of
https://github.com/alexbelgium/hassio-addons.git
synced 2026-06-16 04:19:13 +02:00
Merge pull request #2201 from alexbelgium/codex/fix-meilisearch-exit-error
Fix Meilisearch startup supervision
This commit is contained in:
@@ -1,3 +1,5 @@
|
|||||||
|
## v5.0_beta5-4 (15-11-2025)
|
||||||
|
- Increment version for rebuilt add-on
|
||||||
## v5.0_beta5-3 (15-11-2025)
|
## v5.0_beta5-3 (15-11-2025)
|
||||||
- Minor bugs fixed
|
- Minor bugs fixed
|
||||||
## v5.0_beta6 (06-01-2025)
|
## v5.0_beta6 (06-01-2025)
|
||||||
|
|||||||
@@ -107,5 +107,5 @@ services:
|
|||||||
- mysql:want
|
- mysql:want
|
||||||
slug: monica
|
slug: monica
|
||||||
url: https://github.com/alexbelgium/hassio-addons/tree/master/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]"
|
webui: "[PROTO:ssl]://[HOST]:[PORT:80]"
|
||||||
|
|||||||
@@ -152,6 +152,52 @@ if [[ "${MEILISEARCH_LOCAL}" == true ]]; then
|
|||||||
S6_SUPERVISED_DIR="/var/run/s6/services"
|
S6_SUPERVISED_DIR="/var/run/s6/services"
|
||||||
fi
|
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=(
|
MEILISEARCH_CMD=(
|
||||||
env \
|
env \
|
||||||
MEILI_ENV="${MEILISEARCH_ENVIRONMENT}" \
|
MEILI_ENV="${MEILISEARCH_ENVIRONMENT}" \
|
||||||
@@ -168,19 +214,20 @@ if [[ "${MEILISEARCH_LOCAL}" == true ]]; then
|
|||||||
"${MEILISEARCH_CMD[@]}" &
|
"${MEILISEARCH_CMD[@]}" &
|
||||||
MEILISEARCH_PID=$!
|
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::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"
|
bashio::log.info "Waiting for Meilisearch health endpoint"
|
||||||
MEILISEARCH_HEALTH_URL="${MEILISEARCH_URL%/}/health"
|
MEILISEARCH_HEALTH_URL="${MEILISEARCH_URL%/}/health"
|
||||||
@@ -189,12 +236,13 @@ if [[ "${MEILISEARCH_LOCAL}" == true ]]; then
|
|||||||
bashio::log.info "Meilisearch is ready"
|
bashio::log.info "Meilisearch is ready"
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
sleep 1
|
meilisearch_ensure_running
|
||||||
|
|
||||||
if [ "${attempt}" -eq 30 ]; then
|
if [ "${attempt}" -eq 30 ]; then
|
||||||
bashio::log.error "Meilisearch did not become ready in time. Stopping add-on."
|
meilisearch_fail "Meilisearch did not become ready in time. Stopping add-on."
|
||||||
s6-svscanctl -t "${S6_SUPERVISED_DIR}"
|
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
sleep 1
|
||||||
done
|
done
|
||||||
else
|
else
|
||||||
bashio::log.info "Detected external Meilisearch endpoint (${MEILISEARCH_URL}); skipping bundled service startup"
|
bashio::log.info "Detected external Meilisearch endpoint (${MEILISEARCH_URL}); skipping bundled service startup"
|
||||||
|
|||||||
Reference in New Issue
Block a user