Last active
May 14, 2021 14:43
-
-
Save rcj4747/ec45687b860cd4e5b718e8764e67d436 to your computer and use it in GitHub Desktop.
Run a command and report status to https://healthchecks.io
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -eu | |
set -o pipefail | |
# Run a command and report status to https://healthchecks.io | |
usage() { | |
echo "Usage: $0 <healthchecks.io UUID> <command>" | |
exit 1 | |
} | |
trap usage EXIT | |
URL="https://hc-ping.com/${1:?No UUID provided}" | |
shift | |
trap - EXIT | |
OUTPUT="" | |
healthcheck() { | |
# Log output is limited to 10,000 bytes, so let's send the tail | |
# as that's likely more useful for debugging | |
OUTPUT=$(echo "${OUTPUT}" | tail --bytes=10000 -) | |
curl \ | |
--fail --silent --show-error \ | |
--retry 5 -o /dev/null \ | |
--data-raw "${OUTPUT}" \ | |
$1 | |
} | |
report_start() { | |
healthcheck "${URL}/start" | |
} | |
report_rc() { | |
RC=$? | |
healthcheck "${URL}/${RC}" | |
exit ${RC} | |
} | |
trap report_rc EXIT | |
healthcheck "$URL/start" | |
# Run command and store output in $OUTPUT for logging at healthcheck.io | |
OUTPUT=$($@ 2>&1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I use this in my crontab to wrap jobs. The tools like this in the docs @ https://healthchecks.io/docs/resources/ all were trying to do too much.