ops-recipes/scripts/comments-health.sh

33 lines
676 B
Bash
Executable file

#!/bin/sh
set -eu
BASE_URL=${1:-${BLOG_URL:-}}
COOKIE_JAR=${COOKIE_JAR:-}
COMMENTS_HEALTH_URL=${COMMENTS_HEALTH_URL:-}
if [ -z "$BASE_URL" ]; then
printf 'BLOG_URL (o primo argomento) obbligatorio\n' >&2
exit 2
fi
base=${BASE_URL%/}
auth_args=""
if [ -n "$COOKIE_JAR" ]; then
auth_args="-b $COOKIE_JAR"
fi
me=$(curl -sS $auth_args -o /dev/null -w '%{http_code}' "$base/api/me")
if [ -n "$COMMENTS_HEALTH_URL" ]; then
health=$(curl -sS -o /dev/null -w '%{http_code}' "$COMMENTS_HEALTH_URL")
printf 'healthz=%s me=%s\n' "$health" "$me"
[ "$health" = "200" ] || exit 1
else
printf 'me=%s\n' "$me"
fi
case "$me" in
200|302|401) exit 0 ;;
*) exit 1 ;;
esac