diff options
author | Timotej S <6674623+underhood@users.noreply.github.com> | 2021-01-15 15:21:12 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-15 15:21:12 +0100 |
commit | 5a898b28c9a82ad39d5442568b71a8306f6d2ae9 (patch) | |
tree | 62b1dedfb2fe288ca7d86958bd1610ce6ed1363c /claim | |
parent | a21119469b21513a84933780d534b9105d10daff (diff) |
Claiming retry/backoff (#10482)
* claiming retry/backoff logic
Diffstat (limited to 'claim')
-rwxr-xr-x | claim/netdata-claim.sh.in | 53 |
1 files changed, 36 insertions, 17 deletions
diff --git a/claim/netdata-claim.sh.in b/claim/netdata-claim.sh.in index 43f663f8b7..7ac91d7fb5 100755 --- a/claim/netdata-claim.sh.in +++ b/claim/netdata-claim.sh.in @@ -289,26 +289,45 @@ fi if [ "${VERBOSE}" == 1 ]; then echo "${URLCOMMAND} \"${TARGET_URL}\"" fi -eval "${URLCOMMAND} \"${TARGET_URL}\"" >"${CLAIMING_DIR}/tmpout.txt" -URLCOMMAND_EXIT_CODE=$? -if [ "${URLTOOL}" = "wget" ] && [ "${URLCOMMAND_EXIT_CODE}" -eq 8 ] ; then -# We consider the server issuing an error response a successful attempt at communicating - URLCOMMAND_EXIT_CODE=0 -fi -rm -f "${CLAIMING_DIR}/tmpin.txt" +attempt_contact () { + eval "${URLCOMMAND} \"${TARGET_URL}\"" >"${CLAIMING_DIR}/tmpout.txt" + URLCOMMAND_EXIT_CODE=$? + if [ "${URLTOOL}" = "wget" ] && [ "${URLCOMMAND_EXIT_CODE}" -eq 8 ] ; then + # We consider the server issuing an error response a successful attempt at communicating + URLCOMMAND_EXIT_CODE=0 + fi -# Check if URLCOMMAND connected and received reply -if [ "${URLCOMMAND_EXIT_CODE}" -ne 0 ] ; then - echo >&2 "Failed to connect to ${URL_BASE}, return code ${URLCOMMAND_EXIT_CODE}" - rm -f "${CLAIMING_DIR}/tmpout.txt" - exit 4 -fi + # Check if URLCOMMAND connected and received reply + if [ "${URLCOMMAND_EXIT_CODE}" -ne 0 ] ; then + echo >&2 "Failed to connect to ${URL_BASE}, return code ${URLCOMMAND_EXIT_CODE}" + rm -f "${CLAIMING_DIR}/tmpout.txt" + return 4 + fi -if [ "${VERBOSE}" == 1 ] ; then - echo "Response from server:" - cat "${CLAIMING_DIR}/tmpout.txt" -fi + if [ "${VERBOSE}" == 1 ] ; then + echo "Response from server:" + cat "${CLAIMING_DIR}/tmpout.txt" + fi + + return 0 +} + +for i in {1..5} +do + if attempt_contact ; then + echo "Connection attempt $i successful" + break + fi + echo "Connection attempt $i failed. Retry in ${i}s." + if [ "$i" -eq 5 ] ; then + rm -f "${CLAIMING_DIR}/tmpin.txt" + exit 4 + fi + sleep "$i" +done + +rm -f "${CLAIMING_DIR}/tmpin.txt" ERROR_KEY=$(grep "\"errorMsgKey\":" "${CLAIMING_DIR}/tmpout.txt" | awk -F "errorMsgKey\":\"" '{print $2}' | awk -F "\"" '{print $1}') case ${ERROR_KEY} in |