Files
argus-installer/healthcheck.sh
T
tech f5d4852ad8 fix: hex password generation, safe DATABASE_URL, consistent /opt/argus default
Root cause of a real production failure on the first live install
(wap-proxy, 2026-07-25): DB_PASSWORD was generated with
`openssl rand -base64 24`, which can produce '/', '+', or '=' --
docker-compose.yml then naively interpolated the raw password into
postgres://postgres:${DB_PASSWORD}@db:5432/..., and a generated
password containing '/' broke the connection string outright. The API
never became healthy; log ingestion failed completely.

- install.sh now generates with `openssl rand -hex 32` (always
  [0-9a-f], can't produce this class of character). Same fix applied
  everywhere else openssl-rand-base64-24 was referenced.
- docker-compose.yml no longer builds DATABASE_URL by string
  interpolation -- DB_PASSWORD is passed as its own var and the API
  assembles the connection string safely internally using
  net/url.UserPassword (proper percent-encoding), a second,
  independent layer so the installer doesn't rely on the password
  generator alone. See the matching argus-appliance commit for the
  Go-side change and its regression test.
- backup.sh/healthcheck.sh/restore.sh/uninstall.sh still defaulted
  ARGUS_INSTALL_DIR to $HOME/argus, inconsistent with install.sh/
  update.sh's own /opt/argus default (changed in an earlier commit
  this session) -- confirmed live on the same install: healthcheck.sh
  and uninstall.sh reported "no installation found" when run from the
  real, correct directory. All five scripts now agree on /opt/argus.

Corresponding argus-appliance fix (config.go's buildDatabaseURL, v3.73.1)
already built and pushed to git-cloud.weboria.eu/weboria/argus-api.
2026-07-25 17:43:08 +00:00

72 lines
2.4 KiB
Bash
Executable File

#!/usr/bin/env bash
#
# ARGUS health check — reports the status of every component.
#
# cd /opt/argus && ./healthcheck.sh
#
set -euo pipefail
INSTALL_DIR="${ARGUS_INSTALL_DIR:-/opt/argus}"
bold() { printf '\033[1m%s\033[0m\n' "$1"; }
ok() { printf ' \033[32m✓\033[0m %s\n' "$1"; }
bad() { printf ' \033[31m✗\033[0m %s\n' "$1"; }
fail() { printf ' \033[31m✗\033[0m %s\n' "$1" >&2; exit 1; }
[ -f "$INSTALL_DIR/docker-compose.yml" ] || fail "No ARGUS installation found at $INSTALL_DIR (set ARGUS_INSTALL_DIR if you installed elsewhere)."
cd "$INSTALL_DIR"
bold "ARGUS Health Check"
echo
EXIT_CODE=0
bold "Containers"
for svc in db valkey docker-socket-proxy api ui nginx; do
STATE="$(docker compose ps --format json "$svc" 2>/dev/null | grep -oP '"State"\s*:\s*"\K[^"]+' || echo "")"
HEALTH="$(docker compose ps --format json "$svc" 2>/dev/null | grep -oP '"Health"\s*:\s*"\K[^"]+' || echo "")"
if [ "$STATE" = "running" ] && { [ -z "$HEALTH" ] || [ "$HEALTH" = "healthy" ]; }; then
ok "$svc — running${HEALTH:+ ($HEALTH)}"
elif [ -z "$STATE" ]; then
bad "$svc — not found"
EXIT_CODE=1
else
bad "$svc$STATE${HEALTH:+ ($HEALTH)}"
EXIT_CODE=1
fi
done
echo
bold "API"
API_HOST_PORT="$(grep -oP '^API_HOST_PORT=\K.*' .env 2>/dev/null || true)"
API_HOST_PORT="${API_HOST_PORT:-9080}"
HEALTH_JSON="$(curl -fsS "http://127.0.0.1:${API_HOST_PORT}/health" 2>/dev/null || true)"
if [ -n "$HEALTH_JSON" ]; then
VERSION="$(printf '%s' "$HEALTH_JSON" | grep -oP '"version"\s*:\s*"\K[^"]+' || echo "?")"
DB_STATUS="$(printf '%s' "$HEALTH_JSON" | grep -oP '"database"\s*:\s*"\K[^"]+' || echo "?")"
CACHE_STATUS="$(printf '%s' "$HEALTH_JSON" | grep -oP '"cache"\s*:\s*"\K[^"]+' || echo "?")"
ok "API reachable — version ${VERSION}, database: ${DB_STATUS}, cache: ${CACHE_STATUS}"
else
bad "API not reachable on http://127.0.0.1:${API_HOST_PORT}/health"
EXIT_CODE=1
fi
echo
UI_PORT="$(grep -oP '^UI_PORT=\K.*' .env 2>/dev/null || true)"
UI_PORT="${UI_PORT:-81}"
bold "Admin panel"
if curl -fsSk -o /dev/null "https://127.0.0.1:${UI_PORT}" 2>/dev/null; then
ok "Reachable at https://localhost:${UI_PORT}"
else
bad "Not reachable at https://localhost:${UI_PORT}"
EXIT_CODE=1
fi
echo
if [ "$EXIT_CODE" = 0 ]; then
bold "All checks passed."
else
bold "One or more checks failed — see above. 'docker compose logs <service>' for details."
fi
exit "$EXIT_CODE"