From 6ec25686412d538a40f38a1c3e9dbd2e49cde897 Mon Sep 17 00:00:00 2001 From: xcwang <1366993017@qq.com> Date: Thu, 12 Oct 2023 15:17:55 +0800 Subject: [PATCH] =?UTF-8?q?feature:=20=20=E5=AE=89=E8=A3=85=E8=84=9A?= =?UTF-8?q?=E6=9C=AC=E5=81=A5=E5=BA=B7=E6=A3=80=E6=9F=A5=E9=87=8D=E8=AF=95?= =?UTF-8?q?=E6=9C=BA=E5=88=B6=20(closed=20#1854)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../agent_tools/agent2/setup_agent.sh | 45 ++++++++++++------- .../agent_tools/agent2/setup_proxy.sh | 43 ++++++++++++------ 2 files changed, 59 insertions(+), 29 deletions(-) diff --git a/script_tools/agent_tools/agent2/setup_agent.sh b/script_tools/agent_tools/agent2/setup_agent.sh index 5560e21d8..571473ba2 100755 --- a/script_tools/agent_tools/agent2/setup_agent.sh +++ b/script_tools/agent_tools/agent2/setup_agent.sh @@ -275,27 +275,42 @@ is_process_ok () { } check_heathz_by_gse () { - local result report_result - if [ -f "${GSE_AGENT_CONFIG_PATH}" ]; then - result=$("${AGENT_SETUP_PATH}"/bin/gse_agent -f "${GSE_AGENT_CONFIG_PATH}" --healthz) - else - result=$("${AGENT_SETUP_PATH}"/bin/gse_agent --healthz) - fi - execution_code=$? + local SLEEP_TIME=1 RETRY_COUNT=0 + + for i in {0..2}; do + local result execution_code + if [ -f "${GSE_AGENT_CONFIG_PATH}" ]; then + result=$("${AGENT_SETUP_PATH}"/bin/gse_agent -f "${GSE_AGENT_CONFIG_PATH}" --healthz 1) + else + result=$("${AGENT_SETUP_PATH}"/bin/gse_agent --healthz 1) + fi + execution_code=$? + if [[ "${execution_code}" -eq 0 ]]; then + break + else + sleep "${SLEEP_TIME}" + RETRY_COUNT=$((RETRY_COUNT + 1)) + if [[ "${RETRY_COUNT}" -ge 3 ]]; then + log healthz_check INFO "gse_agent healthz check return code: ${execution_code}" + report_result=$(awk -F': ' '{print $2}' <<< "$result") + if is_base64_command_exist; then + report_result=$(echo "$result" | base64 -w 0) + else + report_result=$(echo "$result" | tr "\"" "\'") + fi + log report_healthz INFO "${report_result}" + fail healthz_check FAILED "gse healthz check failed with retry count: $RETRY_COUNT" + fi + fi + done report_result=$(awk -F': ' '{print $2}' <<< "$result") if is_base64_command_exist; then report_result=$(echo "$result" | base64 -w 0) else report_result=$(echo "$result" | tr "\"" "\'") fi - if [ "${execution_code}" -eq 0 ]; then - log report_healthz - "${report_result}" - log healthz_check INFO "gse_agent healthz check success" - else - warn report_healthz INFO "gse_agent healthz check return code: ${execution_code}" - warn report_healthz - "${report_result}" - fail healthz_check FAILED "gse healthz check failed." - fi + log report_healthz - "${report_result}" + log healthz_check INFO "gse_agent healthz check success" } remove_crontab () { diff --git a/script_tools/agent_tools/agent2/setup_proxy.sh b/script_tools/agent_tools/agent2/setup_proxy.sh index 4ab03f703..dc90f5090 100755 --- a/script_tools/agent_tools/agent2/setup_proxy.sh +++ b/script_tools/agent_tools/agent2/setup_proxy.sh @@ -407,27 +407,42 @@ is_base64_command_exist() { } check_healthz_by_gse () { - local result - if [ -f "${GSE_AGENT_CONFIG_PATH}" ]; then - result=$("${AGENT_SETUP_PATH}"/bin/gse_agent -f "${GSE_AGENT_CONFIG_PATH}" --healthz) - else - result=$("${AGENT_SETUP_PATH}"/bin/gse_agent --healthz) - fi - execution_code=$? + local SLEEP_TIME=1 RETRY_COUNT=0 + for i in {0..2}; do + local result execution_code + if [ -f "${GSE_AGENT_CONFIG_PATH}" ]; then + result=$("${AGENT_SETUP_PATH}"/bin/gse_agent -f "${GSE_AGENT_CONFIG_PATH}" --healthz 1) + else + result=$("${AGENT_SETUP_PATH}"/bin/gse_agent --healthz 1) + fi + execution_code=$? + if [[ "${execution_code}" -eq 0 ]]; then + break + else + sleep "${SLEEP_TIME}" + RETRY_COUNT=$((RETRY_COUNT + 1)) + if [[ "${RETRY_COUNT}" -ge 3 ]]; then + log healthz_check INFO "gse_agent healthz check return code: ${execution_code}" + report_result=$(awk -F': ' '{print $2}' <<< "$result") + if is_base64_command_exist; then + report_result=$(echo "$result" | base64 -w 0) + else + report_result=$(echo "$result" | tr "\"" "\'") + fi + log report_healthz INFO "${report_result}" + fail healthz_check FAILED "gse healthz check failed with retry count: $RETRY_COUNT" + fi + fi + done report_result=$(awk -F': ' '{print $2}' <<< "$result") if is_base64_command_exist; then report_result=$(echo "$result" | base64 -w 0) else report_result=$(echo "$result" | tr "\"" "\'") fi - if [ "${execution_code}" -eq 0 ]; then - log report_healthz - "${report_result}" - log healthz_check INFO "gse_agent healthz check success" - else - warn report_healthz INFO "gse_agent healthz check return code: ${execution_code}" - warn report_healthz - "${report_result}" - fail healthz_check FAILED "gse healthz check failed." + log report_healthz - "${report_result}" + log healthz_check INFO "gse_agent healthz check success" fi }