You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

34 lines
939 B

#!/usr/bin/env bash
set -euo pipefail
SERVICE_NAME="${SERVICE_NAME:-hw}"
APP_PORT="${APP_PORT:-8000}"
HEALTHCHECK_URL="${HEALTHCHECK_URL:-http://127.0.0.1/health}"
fail() {
printf 'Verification failed: %s\n' "$1" >&2
exit 1
}
main() {
if ! systemctl is-active --quiet "$SERVICE_NAME"; then
fail "systemd service '$SERVICE_NAME' is not active"
fi
if ! ss -tln | grep -q ":${APP_PORT} "; then
fail "nothing is listening on TCP port ${APP_PORT}"
fi
health_payload="$(curl --fail --silent --show-error --max-time 10 "$HEALTHCHECK_URL")" || fail "healthcheck request failed: $HEALTHCHECK_URL"
if ! printf '%s' "$health_payload" | grep -q '"status":"ok"\|"status": "ok"'; then
fail "healthcheck response does not contain status=ok"
fi
printf 'Verification succeeded.\n'
printf 'Service: %s\n' "$SERVICE_NAME"
printf 'Port: %s\n' "$APP_PORT"
printf 'Healthcheck: %s\n' "$HEALTHCHECK_URL"
}
main "$@"