Skip to content

Commit

Permalink
optimization: 对动态寻址的相同IP主机安装Agent时的处理逻辑优化 (closed #1281)
Browse files Browse the repository at this point in the history
  • Loading branch information
CohleRustW authored and ZhuoZhuoCrayon committed Dec 22, 2022
1 parent 7752f14 commit bd0c0c5
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 9 deletions.
3 changes: 3 additions & 0 deletions dev_log/2.2.32/xcwang_202211291040.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
optimization:
- "对动态寻址的相同IP主机安装Agent时的处理逻辑优化 (closed #1281)"
24 changes: 19 additions & 5 deletions script_tools/agent_tools/agent2/setup_agent.bat
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ rem DEFAULT DEFINITION
set PKG_NAME=
set CLOUD_ID=
set UNINSTALL=1
set UNREGISTER_AGENT_ID=1
set BACKUP_CONFIG_FILE=procinfo.json

:CheckOpts
Expand Down Expand Up @@ -41,6 +42,7 @@ if "%1" EQU "-K" (set TRACKER_PORT=%~2) && shift && shift && goto CheckOpts
if "%1" EQU "-U" (set INSTALL_USER=%~2) && shift && shift && goto CheckOpts
if "%1" EQU "-P" (set INSTALL_PASSWORD=%~2) && shift && shift && goto CheckOpts
if "%1" EQU "-R" (set UNINSTALL=0) && shift && shift && goto CheckOpts
if "%1" EQU "-F" (set UNREGISTER_AGENT_ID=0) && shift && goto CheckOpts
if "%1" NEQ "" echo Invalid option: "%1" && goto :EOF && exit /B 1
rem if "%1" EQU "-R" goto remove_agent_pro

Expand Down Expand Up @@ -228,7 +230,7 @@ goto :EOF
if "!network_not_reachable!" == "" (
echo "reachable"
) else (
call :print FAIL check_env FAILED "%network_not_reachable% is not reachable"
call :print FAIL check_env FAILED "%network_not_reachable% is not reachable"
call :multi_report_step_status
exit /b 1
)
Expand Down Expand Up @@ -1103,6 +1105,11 @@ goto :EOF
call :multi_report_step_status
exit /b 1
)

if %UNREGISTER_AGENT_ID% EQU 0 (
call :unregister_agent_id SKIP
)

%gse_winagent_home%\\agent\\bin\\gse_agent.exe --agent-id -f %GSE_AGENT_ETC_DIR%\\gse_agent.conf
if %errorlevel% EQU 0 (
call :re_register_agent_id
Expand Down Expand Up @@ -1214,6 +1221,7 @@ goto :EOF
goto :EOF

:unregister_agent_id
(set skip=%1)
if NOT EXIST %gse_winagent_home%\\agent\\bin\\gse_agent.exe (
call :print FAIL unregister_agent_id FAILED "%gse_winagent_home%\\agent\\bin\\gse_agent.exe not exists"
call :multi_report_step_status
Expand All @@ -1232,12 +1240,17 @@ goto :EOF
%gse_winagent_home%\\agent\\bin\\gse_agent.exe --unregister
)
if %errorlevel% EQU 0 (
call :print INFO register_agent_id - "unregister agent id success"
call :print INFO unregister_agent_id - "unregister agent id success"
call :multi_report_step_status
) else (
call :print FAIL register_agent_id FAILED "unregister agent id failed"
call :multi_report_step_status
exit /b 1
if "%skip%" == "SKIP": (
call :print WARN unregister_agent_id - "unregister agent id failed, but skip it"
call :multi_report_step_status
) else (
call :print FAIL unregister_agent_id FAILED "unregister agent id failed"
call :multi_report_step_status
exit /b 1
)
)
goto :EOF

Expand Down Expand Up @@ -1350,6 +1363,7 @@ goto :EOF
echo -O CLUSTER_PORT
echo -E FILE_SVR_PORT
echo -R UNINSTALL_AGENT
echo -F UNREGISTER_AGENT_ID [optional]
goto :EOF

:EOF
18 changes: 16 additions & 2 deletions script_tools/agent_tools/agent2/setup_agent.sh
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,12 @@ register_agent_id () {
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)
Expand All @@ -346,6 +352,7 @@ register_agent_id () {
}

unregister_agent_id () {
local skip="$1"
log unregister_agent_id - "trying to unregister agent id"
if [ -f "$AGENT_SETUP_PATH/bin/gse_agent" ]; then
if [ -f "${GSE_AGENT_CONFIG_PATH}" ]; then
Expand All @@ -357,7 +364,11 @@ unregister_agent_id () {
if [[ $? -eq 0 ]]; then
log unregister_agent_id SUCCESS "unregister agent id succeed"
else
fail unregister_agent_id FAILED "unregister agent id failed, error: ${unregister_agent_id_result}"
if [[ "${skip}" == "SKIP" ]]; then
warn unregister_agent_id - "unregister agent id failed, but skip it. error: ${unregister_agent_id_result}"
else
fail unregister_agent_id FAILED "unregister agent id failed, error: ${unregister_agent_id_result}"
fi
fi
else
log unregister_agent_id FAILED "gse_agent file not exists in $AGENT_SETUP_PATH/bin"
Expand Down Expand Up @@ -756,6 +767,7 @@ _help () {
echo " -S BT_PORT_START"
echo " -Z BT_PORT_END"
echo " -K TRACKER_PORT"
echo " -F UNREGISTER_AGENT_ID [optional]"

exit 0
}
Expand Down Expand Up @@ -783,6 +795,7 @@ AGENT_SETUP_PATH="/usr/local/gse/${NODE_TYPE}"
CURR_PID=$$
OVERIDE=false
REMOVE=false
UNREGISTER_AGENT_ID=false
CALLBACK_URL=
AGENT_PID=
DEBUG=
Expand All @@ -792,7 +805,7 @@ LOG_RPT_CNT=0
BULK_LOG_SIZE=3

# main program
while getopts n:t:I:i:l:s:uc:r:x:p:e:a:k:N:v:oT:RDO:E:A:V:B:S:Z:K: arg; do
while getopts n:t:I:i:l:s:uc:r:x:p:e:a:k:N:v:oT:RDO:E:A:V:B:S:Z:K:F arg; do
case $arg in
n) NAME="$OPTARG" ;;
t) VERSION="$OPTARG" ;;
Expand Down Expand Up @@ -821,6 +834,7 @@ while getopts n:t:I:i:l:s:uc:r:x:p:e:a:k:N:v:oT:RDO:E:A:V:B:S:Z:K: arg; do
S) BT_PORT_START=$OPTARG ;;
Z) BT_PORT_END=$OPTARG ;;
K) TRACKER_PORT=$OPTARG ;;
F) UNREGISTER_AGENT_ID=TRUE ;;
*) _help ;;
esac
done
Expand Down
17 changes: 15 additions & 2 deletions script_tools/agent_tools/agent2/setup_proxy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,11 @@ register_agent_id () {
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_agent_id=$($AGENT_SETUP_PATH/bin/gse_agent -f "${GSE_AGENT_CONFIG_PATH}" --register 2>&1)
Expand All @@ -337,6 +342,7 @@ register_agent_id () {
}

unregister_agent_id () {
local skip="$1"
log unregister_agent_id - "trying to unregister agent id"
if [ -f "$AGENT_SETUP_PATH/bin/gse_agent" ]; then
if [ -f "${GSE_AGENT_CONFIG_PATH}" ]; then
Expand All @@ -348,7 +354,11 @@ unregister_agent_id () {
if [[ $? -eq 0 ]]; then
log unregister_agent_id SUCCESS "unregister agent id succeed"
else
fail unregister_agent_id FAILED "unregister agent id failed, error: ${unregister_agent_id_result}"
if [[ "${skip}" == "SKIP" ]]; then
warn unregister_agent_id - "unregister agent id failed, but skip it. error: ${unregister_agent_id_result}"
else
fail unregister_agent_id FAILED "unregister agent id failed, error: ${unregister_agent_id_result}"
fi
fi
else
log unregister_agent_id FAILED "gse_agent file not exists in $AGENT_SETUP_PATH/bin"
Expand Down Expand Up @@ -700,6 +710,7 @@ _help () {
echo " -S BT_PORT_START"
echo " -Z BT_PORT_END"
echo " -K TRACKER_PORT"
echo " -F UNREGISTER_AGENT_ID [optional]"

exit 0
}
Expand All @@ -723,12 +734,13 @@ AGENT_SETUP_PATH="/usr/local/gse/${NODE_TYPE}"
CURR_PID=$$
UPGRADE=false
OVERIDE=false
UNREGISTER_AGENT_ID=false
REMOVE=false
CALLBACK_URL=
AGENT_PID=

# main program
while getopts n:t:I:i:l:s:uc:r:x:p:e:a:k:N:g:v:oT:RO:E:A:V:B:S:Z:K: arg; do
while getopts n:t:I:i:l:s:uc:r:x:p:e:a:k:N:g:v:oT:RO:E:A:V:B:S:Z:K:F arg; do
case $arg in
n) export NAME="$OPTARG" ;;
t) export VERSION="$OPTARG" ;;
Expand Down Expand Up @@ -759,6 +771,7 @@ while getopts n:t:I:i:l:s:uc:r:x:p:e:a:k:N:g:v:oT:RO:E:A:V:B:S:Z:K: arg; do
S) export BT_PORT_START=$OPTARG ;;
Z) export BT_PORT_END=$OPTARG ;;
K) export TRACKER_PORT=$OPTARG ;;
F) UNREGISTER_AGENT_ID=TRUE ;;
*) _help ;;
esac
done
Expand Down

0 comments on commit bd0c0c5

Please sign in to comment.