diff --git a/dev_log/2.2.32/xcwang_202211291040.yaml b/dev_log/2.2.32/xcwang_202211291040.yaml new file mode 100644 index 000000000..0dbdb1902 --- /dev/null +++ b/dev_log/2.2.32/xcwang_202211291040.yaml @@ -0,0 +1,3 @@ +--- +optimization: + - "对动态寻址的相同IP主机安装Agent时的处理逻辑优化 (closed #1281)" diff --git a/script_tools/agent_tools/agent2/setup_agent.bat b/script_tools/agent_tools/agent2/setup_agent.bat index 9465202b9..36e3052e1 100644 --- a/script_tools/agent_tools/agent2/setup_agent.bat +++ b/script_tools/agent_tools/agent2/setup_agent.bat @@ -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 @@ -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 @@ -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 ) @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/script_tools/agent_tools/agent2/setup_agent.sh b/script_tools/agent_tools/agent2/setup_agent.sh index 69a1d8dec..60df17426 100755 --- a/script_tools/agent_tools/agent2/setup_agent.sh +++ b/script_tools/agent_tools/agent2/setup_agent.sh @@ -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) @@ -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 @@ -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" @@ -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 } @@ -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= @@ -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" ;; @@ -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 diff --git a/script_tools/agent_tools/agent2/setup_proxy.sh b/script_tools/agent_tools/agent2/setup_proxy.sh index e3c654515..f82e394ce 100755 --- a/script_tools/agent_tools/agent2/setup_proxy.sh +++ b/script_tools/agent_tools/agent2/setup_proxy.sh @@ -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) @@ -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 @@ -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" @@ -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 } @@ -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" ;; @@ -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