Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optimization: 注册 agent_id 重试机制 (closed #1609) #1750

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 25 additions & 12 deletions script_tools/agent_tools/agent2/setup_agent.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
36 changes: 25 additions & 11 deletions script_tools/agent_tools/agent2/setup_proxy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 () {
Expand Down