set -euo pipefail
cd /opt/infisical
echo '== compose ps =='
docker compose -f docker-compose.prod.yml ps
echo '== docker inspect restart/status =='
docker inspect infisical-app --format 'state={{.State.Status}} running={{.State.Running}} restarting={{.State.Restarting}} started={{.State.StartedAt}} finished={{.State.FinishedAt}} exit={{.State.ExitCode}} health={{if .State.Health}}{{.State.Health.Status}}{{else}}none{{end}}'
echo '== listeners =='
ss -ltnp | grep -E '8088|18080|8080' || true
echo '== repeated direct container port checks =='
for url in http://127.0.0.1:18080/api/status http://172.18.0.3:8080/api/status; do
  echo "URL=$url"
  for i in $(seq 1 8); do
    printf 'try=%s ' "$i"
    curl -sS --max-time 5 -w ' http_code=%{http_code} exit=%{exitcode}\n' -o /tmp/infisical-health.out "$url" || true
    cat /tmp/infisical-health.out 2>/dev/null || true; echo
    sleep 1
  done
done
echo '== recent app errors/warnings sanitized =='
docker logs --tail 160 infisical-app 2>&1 | sed -E 's/(token|secret|password|key|authorization|cookie)([=: ]+)[^ ,}\"]+/\1\2[REDACTED]/Ig' | tail -120
