56 lines
2.0 KiB
Bash
Executable File
56 lines
2.0 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -Euo pipefail
|
|
|
|
CONFIG_FILE="${XDG_CONFIG_HOME:-$HOME/.config}/hermes-stack-maintenance/config.env"
|
|
STATE_DIR="${XDG_STATE_HOME:-$HOME/.local/state}/hermes-stack-maintenance"
|
|
NOTIFIER="$HOME/.local/libexec/hermes-stack-notify"
|
|
mkdir -p "$STATE_DIR"
|
|
# shellcheck disable=SC1090
|
|
source "$CONFIG_FILE"
|
|
|
|
# Niemals den absichtlich gestoppten Gateway mitten im Update neu starten.
|
|
exec 9>"${XDG_RUNTIME_DIR:-/tmp}/hermes-stack-hermes-update.lock"
|
|
flock -n 9 || exit 0
|
|
|
|
state_file="$STATE_DIR/health-state"
|
|
problems=()
|
|
|
|
if ! systemctl --user is-active --quiet "$GATEWAY_SERVICE"; then
|
|
problems+=("$GATEWAY_SERVICE war inaktiv; Neustart wurde versucht")
|
|
systemctl --user restart "$GATEWAY_SERVICE" || true
|
|
fi
|
|
|
|
if ! hermes gateway status >/dev/null 2>&1; then
|
|
problems+=("Hermes-Gateway antwortete nicht gesund; Neustart wurde versucht")
|
|
systemctl --user restart "$GATEWAY_SERVICE" || true
|
|
fi
|
|
|
|
if [[ "${LLAMA_HEALTH_AUTORESTART:-0}" == 1 ]] &&
|
|
! systemctl --user is-active --quiet "$LLAMA_SERVICE"; then
|
|
problems+=("$LLAMA_SERVICE war inaktiv; Neustart wurde versucht")
|
|
systemctl --user restart "$LLAMA_SERVICE" || true
|
|
fi
|
|
|
|
if ! curl --fail --silent --max-time 10 "$LLAMA_URL/health" |
|
|
jq -e '.status == "ok"' >/dev/null 2>&1; then
|
|
problems+=("llama-server antwortete nicht gesund; kein HTTP-bedingter Neustart laufender Inferenz")
|
|
fi
|
|
|
|
if ((${#problems[@]} == 0)); then
|
|
current="healthy"
|
|
previous="$(cat "$state_file" 2>/dev/null || true)"
|
|
if [[ "$previous" == unhealthy ]]; then
|
|
"$NOTIFIER" "Hermes-Stack: Dienste sind wieder gesund." || true
|
|
fi
|
|
else
|
|
current="unhealthy"
|
|
previous="$(cat "$state_file" 2>/dev/null || true)"
|
|
if [[ "$previous" != unhealthy ]]; then
|
|
message="$(IFS='; '; printf '%s' "${problems[*]}")"
|
|
"$NOTIFIER" "Hermes-Stack: Gesundheitsprüfung fehlgeschlagen. $message. Details: journalctl --user -u $LLAMA_SERVICE -u $GATEWAY_SERVICE" || true
|
|
fi
|
|
fi
|
|
|
|
printf '%s\n' "$current" >"$state_file"
|
|
[[ "$current" == healthy ]]
|