Skip to content

Instantly share code, notes, and snippets.

@scottillogical
Created May 30, 2019 13:15
Show Gist options
  • Save scottillogical/6adc1f292029df775789c799ca8c1ccc to your computer and use it in GitHub Desktop.
Save scottillogical/6adc1f292029df775789c799ca8c1ccc to your computer and use it in GitHub Desktop.
custom diego health checi
#!/bin/sh
TIMEOUT=${HEALTH_CHECK_TIMEOUT:-30}
URL=${HEALTH_CHECK_URL:-localhost:8091/health}
RESPONSE=$(curl --connect-time $TIMEOUT --max-time $TIMEOUT -qs "$URL")
OUTCOME=$?
set -e
if [ ${OUTCOME} -eq 7 ]; then
echo "Failed to connect to ${URL}, cURL returned status ${OUTCOME}. Cheetah may not be started fully yet."
exit $OUTCOME
fi
if [ ${OUTCOME} -ne 0 ]; then
echo "Health check on ${URL}, cURL returned ${OUTCOME}\n${RESPONSE}"
exit $OUTCOME
fi
STATUS=$(echo "${RESPONSE}" | jq -r '.status')
if [ ${STATUS} = "UNHEALTHY" ]; then
echo "One or more health checks failed\n${RESPONSE}"
exit 0
elif [ ${STATUS} = "CRASHED" ]; then
echo "Application crashed\n${RESPONSE}"
exit 1
else
# Either booting up or healthy
exit 0
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment