-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
132 additions
and
22 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,5 +4,6 @@ _data/ | |
bin/ | ||
tmp/ | ||
frontend/config | ||
notes.md | ||
|
||
# Binaries from `go build` |
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/bin/bash | ||
|
||
VERSION=$1 | ||
|
||
if [[ -z "$VERSION" ]]; then | ||
echo "Error! Supply version tag!" | ||
exit 1 | ||
fi | ||
|
||
# read in notes.md | ||
REL_NOTES=$(cat notes.md) | ||
|
||
read -r -d '' NOTES << EOM | ||
$REL_NOTES | ||
\`\`\` | ||
docker pull ghcr.io/benc-uk/nanomon-api:$VERSION | ||
docker pull ghcr.io/benc-uk/nanomon-frontend:$VERSION | ||
docker pull ghcr.io/benc-uk/nanomon-runner:$VERSION | ||
\`\`\` | ||
EOM | ||
|
||
gh release create "$VERSION" --title "Release v$VERSION" -n "$NOTES" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
#!/bin/bash | ||
|
||
declare -i time=60 | ||
declare -i delay=5 | ||
declare -i count=5 | ||
declare -i okCount=0 | ||
declare -i elapsed=0 | ||
declare isUp="false" | ||
|
||
# Display usage | ||
usage(){ | ||
echo -e "\e[32m╭──────────────────────────────────────────────────────────────╮" | ||
echo -e "│ 🌍 \e[94murl-check.sh \e[96mCheck URL endpoint for HTTP responses 🚀\e[32m │" | ||
echo -e "╰──────────────────────────────────────────────────────────────╯" | ||
echo -e "\n\e[95mParameters:\e[37m" | ||
echo -e " -u, --url \e[33mURL to check (required)\e[37m" | ||
echo -e " [-t, --time] \e[33mMaximum number of seconds to poll for \e[92m(default: 60)\e[37m" | ||
echo -e " [-d, --delay] \e[33mDelay in seconds between requests \e[92m(default: 5)\e[37m" | ||
echo -e " [-c, --count] \e[33mHow many successes to receive before exiting \e[92m(default: 5)\e[37m" | ||
echo -e " [-s, --search] \e[33mOptional content check, grep for this string in HTTP body \e[92m(default: none)\e[37m" | ||
echo -e " [-h, --help] \e[33mShow this help text\e[37m" | ||
} | ||
|
||
if ! OPTS=$(getopt -o u:t:d:c:s:h --long url:,time:,delay:,count:,search:,help -n 'parse-options' -- "$@"); then echo "Failed parsing options." >&2 ; usage; exit 1 ; fi | ||
eval set -- "$OPTS" | ||
|
||
while true; do | ||
case "$1" in | ||
-u | --url ) url="$2"; shift; shift;; | ||
-t | --time ) time="$2"; shift; shift;; | ||
-d | --delay ) delay="$2"; shift; shift;; | ||
-c | --count ) count="$2"; shift; shift;; | ||
-s | --search ) search="$2"; shift; shift;; | ||
-h | --help ) HELP=true; shift ;; | ||
-- ) shift; break ;; | ||
* ) break ;; | ||
esac | ||
done | ||
|
||
if [[ ${HELP} = true ]] || [ -z "${url}" ]; then | ||
usage | ||
exit 0 | ||
fi | ||
|
||
# Check for impossible parameter combination ie. too many checks and delays in given time limit | ||
if (( delay * count > time)); then | ||
echo -e "\e[31m### Error! The time ($time) provided is too short given the delay ($delay) and count ($count)\e[0m" | ||
exit 1 | ||
fi | ||
|
||
echo -e "\n\e[36m### Polling \e[33m$url\e[36m for ${time}s, to get $count OK results, with a ${delay}s delay\e[0m\n" | ||
|
||
# Generate tmp filename | ||
tmpfile=$(echo "$url" | md5sum) | ||
|
||
# Main loop | ||
while [ "$isUp" != "true" ] | ||
do | ||
# Break out of loop if max time has elapsed | ||
if (( elapsed >= time )); then break; fi | ||
timestamp=$(date "+%Y/%m/%d %H:%M:%S") | ||
|
||
# Main CURL test, output to file and return http_code | ||
urlstatus=$(curl -o "/tmp/$tmpfile" --silent --write-out '%{http_code}' "$url") | ||
|
||
if [ "$urlstatus" -eq 000 ]; then | ||
# Code 000 means DNS, network error or malformed URL | ||
msg="\e[95mSite not found or other error" | ||
else | ||
if (( urlstatus >= 200 )) && (( urlstatus < 300 )); then | ||
# Check returned content with grep if check specified | ||
if [ -n "$search" ]; then | ||
# Only count as a success if string grep passed | ||
if grep -q "$search" "/tmp/$tmpfile"; then | ||
(( okCount=okCount + 1 )) | ||
msg="✅ \e[32m$urlstatus 🔍 Content check for '$search' passed" | ||
else | ||
msg="❌ \e[91m$urlstatus 🔍 Content check for '$search' failed" | ||
fi | ||
else | ||
# Good status code | ||
((okCount=okCount + 1)) | ||
msg="✅ \e[32m$urlstatus " | ||
fi | ||
|
||
if (( okCount >= count )); then isUp="true"; fi | ||
else | ||
# Bad status code | ||
msg="❌ \e[91m$urlstatus " | ||
fi | ||
fi | ||
|
||
# Output message + timestamp then delay | ||
echo -e "### $timestamp: $msg\e[0m" | ||
# if isUp false then delay | ||
if [ "$isUp" != "true" ]; then sleep "$delay"; fi | ||
((elapsed=elapsed + delay)) | ||
done | ||
|
||
rm "/tmp/$tmpfile" > /dev/null 2>&1 | ||
# Final result check | ||
if [ "$isUp" == "true" ]; then | ||
echo -e "\n\e[32m### Result: $url is UP! 🤩\e[0m" | ||
exit 0 | ||
else | ||
echo -e "\n\e[91m### Result: $url is DOWN! 😢\e[0m" | ||
exit 1 | ||
fi |