From caca6c9433842099dfb973a622ac4d48cdf94394 Mon Sep 17 00:00:00 2001 From: xcwang <1366993017@qq.com> Date: Thu, 17 Aug 2023 16:17:03 +0800 Subject: [PATCH] =?UTF-8?q?optimization:=20=20=E6=B3=A8=E5=86=8C=20agent?= =?UTF-8?q?=5Fid=20=E9=87=8D=E8=AF=95=E6=9C=BA=E5=88=B6=20(closed=20#1609)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../agent_tools/agent2/setup_agent.sh | 37 +++++++++++++------ .../agent_tools/agent2/setup_proxy.sh | 36 ++++++++++++------ 2 files changed, 50 insertions(+), 23 deletions(-) diff --git a/script_tools/agent_tools/agent2/setup_agent.sh b/script_tools/agent_tools/agent2/setup_agent.sh index c48dc9c4d..dc9bd4a57 100755 --- a/script_tools/agent_tools/agent2/setup_agent.sh +++ b/script_tools/agent_tools/agent2/setup_agent.sh @@ -326,29 +326,42 @@ setup_startup_scripts () { echo "[ -f $AGENT_SETUP_PATH/bin/gsectl ] && $AGENT_SETUP_PATH/bin/gsectl start >/var/log/gse_start.log 2>&1" >>$rcfile } +registe_agent_with_excepte () { + local SLEEP_TIME=1 RETRY_COUNT=0 + + for i in {0..2}; do + local registe_result registe_code + if [ -f "${GSE_AGENT_CONFIG_PATH}" ]; then + registe_result=$($AGENT_SETUP_PATH/bin/gse_agent -f "${GSE_AGENT_CONFIG_PATH}" --register 2>&1) + else + registe_result=$($AGENT_SETUP_PATH/bin/gse_agent --register 2>&1) + fi + registe_code=$? + if [[ "${registe_code}" -eq 0 ]] && [[ ! "${registe_result}" =~ "overwrite" ]]; then + log report_agent_id DONE "$registe_result" + break + else + sleep "${SLEEP_TIME}" + RETRY_COUNT=$((RETRY_COUNT + 1)) + if [[ "${RETRY_COUNT}" -ge 3 ]]; then + fail register_agent_id FAILED "register agent id failed, error: ${registe_result}" + fi + fi + done +} + register_agent_id () { if [ ! -f "$AGENT_SETUP_PATH/bin/gse_agent" ]; then fail register_agent_id FAILED "gse_agent file not exists in $AGENT_SETUP_PATH/bin" fi - if [[ "${UNREGISTER_AGENT_ID}" == "TRUE" ]]; then log register_agent_id - "trying to unregister agent id" unregister_agent_id SKIP fi log register_agent_id - "trying to register agent id" - if [ -f "${GSE_AGENT_CONFIG_PATH}" ]; then - registe_result=$($AGENT_SETUP_PATH/bin/gse_agent -f "${GSE_AGENT_CONFIG_PATH}" --register 2>&1) - else - registe_result=$($AGENT_SETUP_PATH/bin/gse_agent --register 2>&1) - fi - - if [[ $? -ne 0 ]]; then - fail register_agent_id FAILED "register agent id failed, error: ${registe_result}" - else - log report_agent_id DONE "$registe_result" - fi + registe_agent_with_excepte } unregister_agent_id () { diff --git a/script_tools/agent_tools/agent2/setup_proxy.sh b/script_tools/agent_tools/agent2/setup_proxy.sh index 62b2c3a99..820fbb904 100755 --- a/script_tools/agent_tools/agent2/setup_proxy.sh +++ b/script_tools/agent_tools/agent2/setup_proxy.sh @@ -317,6 +317,30 @@ start_proxy () { done } +registe_agent_with_excepte () { + local SLEEP_TIME=1 RETRY_COUNT=0 + + for i in {0..2}; do + local registe_result registe_code + if [ -f "${GSE_AGENT_CONFIG_PATH}" ]; then + registe_result=$($AGENT_SETUP_PATH/bin/gse_agent -f "${GSE_AGENT_CONFIG_PATH}" --register 2>&1) + else + registe_result=$($AGENT_SETUP_PATH/bin/gse_agent --register 2>&1) + fi + registe_code=$? + if [[ "${registe_code}" -eq 0 ]] && [[ ! "${registe_result}" =~ "overwrite" ]]; then + log report_agent_id DONE "$registe_result" + break + else + sleep "${SLEEP_TIME}" + RETRY_COUNT=$((RETRY_COUNT + 1)) + if [[ "${RETRY_COUNT}" -ge 3 ]]; then + fail register_agent_id FAILED "register agent id failed, error: ${registe_result}" + fi + fi + done +} + register_agent_id () { if [ ! -f "$AGENT_SETUP_PATH/bin/gse_agent" ]; then fail register_agent_id FAILED "gse_agent file not exists in $AGENT_SETUP_PATH/bin" @@ -328,17 +352,7 @@ register_agent_id () { fi log register_agent_id - "trying to register agent id" - if [ -f "${GSE_AGENT_CONFIG_PATH}" ]; then - registe_agent_id=$($AGENT_SETUP_PATH/bin/gse_agent -f "${GSE_AGENT_CONFIG_PATH}" --register 2>&1) - else - registe_agent_id=$($AGENT_SETUP_PATH/bin/gse_agent --register 2>&1) - fi - - if [[ $? -ne 0 ]]; then - fail register_agent_id FAILED "register agent id failed, error: ${registe_agent_id}" - else - log report_agent_id DONE "$registe_agent_id" - fi + registe_agent_with_excepte } unregister_agent_id () {