From a39b9e0598517026b791e3099284780fd40f788f Mon Sep 17 00:00:00 2001 From: yuejiajun <1530620364@qq.com> Date: Thu, 21 Aug 2025 12:10:46 +0800 Subject: [PATCH] quick --- base/Resources/quick.bat | 184 ++++++++++++++++++++++++++------------- 1 file changed, 124 insertions(+), 60 deletions(-) diff --git a/base/Resources/quick.bat b/base/Resources/quick.bat index 6ef69c3..252db9b 100644 --- a/base/Resources/quick.bat +++ b/base/Resources/quick.bat @@ -44,7 +44,24 @@ if defined LOG_TITLE ( ) exit /b 0 -:rar +:DisplaySuccess +timeout /t 3 /nobreak > nul +echo. +echo ======================================== +echo %SERVER_HUMP% Services Successfully Started +echo ======================================== + +for %%i in (%PORT_LIST%) do ( + for /f "tokens=1,2 delims=:" %%a in ("%%i") do ( + echo - %%b Server - Port %%a is listening + ) +) + +echo ======================================== +echo. +exit /b 0 + +:Rar call :RandomStr 16 RAND_NAME set TARGET_DIR=%temp%\!CURRENT_DATE! if not exist "!TARGET_DIR!" mkdir "!TARGET_DIR!" @@ -80,65 +97,6 @@ del %single_pid_tmp%.txt endlocal & set pid=%pid% exit /b 0 -:RandomStr -setlocal -set "len=%~1" -set "varname=%~2" -if "!varname!"=="" set "varname=RAND_STR" - -set "chars=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" -set "random_str=" - -for /l %%i in (1,1,!len!) do ( - set /a rand_index=!random! %% 62 - call set "char=%%chars:~!rand_index!,1%%" - set "random_str=!random_str!!char!" -) - -endlocal & set "%varname%=%random_str%" -exit /b 0 - -:Start -setlocal -set DESCRIPTION=%1 -set SCRIPT_PATH=%2 -set SCRIPT_FILE=%3 - -set PARAMS= -shift /3 -:params_loop -if not "%~1"=="" ( - set "PARAMS=%PARAMS% %~3" - shift - goto params_loop -) - -if exist "%SCRIPT_PATH%\%SCRIPT_FILE%" ( - echo. - call :log_info Starting %DESCRIPTION%... - cd /d "%SCRIPT_PATH%" - start "%DESCRIPTION% Startup" /B cmd /c "%SCRIPT_FILE% %PARAMS%" - if errorlevel 1 ( - call :log_error %DESCRIPTION% start Failed. - pause && exit /b 1 - ) -) else ( - call :log_error Script file not found: %SCRIPT_PATH%\%SCRIPT_FILE% - pause && exit /b 1 -) -endlocal -exit /b 0 - -:GetFormattedTime -for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "datetime=%%a" -set "FormattedTime=%datetime:~0,4%-%datetime:~4,2%-%datetime:~6,2% %datetime:~8,2%:%datetime:~10,2%:%datetime:~12,2%" -exit /b 0 - -:GetDate -for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "datetime=%%a" -set "FormattedDate=%datetime:~0,4%%datetime:~4,2%%datetime:~6,2%" -exit /b 0 - :GetUsageNumberOfPidsByPort setlocal set "PORT=%~1" @@ -209,9 +167,101 @@ del "!PID_LIST_FILE!" 2>nul endlocal & exit /b %UNIQUE_COUNT% +:ListenPortList +set all_ports_up=1 + +for %%i in (%PORT_LIST%) do ( + for /f "tokens=1,2 delims=:" %%a in ("%%i") do ( + set port=%%a + set service=%%b + netstat -an | find ":%%a" > nul + if !errorlevel! neq 0 ( + set all_ports_up=0 + :: call :log_info "!service! Server (Port: %%a) isn't ready..." + ) + ) +) + +if !all_ports_up! equ 1 ( + call :DisplaySuccess + exit /b 0 +) + +set /a counter+=CHECK_INTERVAL +if !counter! geq %MAX_WAIT% ( + call :log_error "Services did not start within !counter! seconds" + exit /b 1 +) + +:: call :log_info "Waiting for services... (!counter!/%MAX_WAIT% seconds)" +echo. +timeout /t %CHECK_INTERVAL% /nobreak > nul +goto ListenPortList + +:RandomStr +setlocal +set "len=%~1" +set "varname=%~2" +if "!varname!"=="" set "varname=RAND_STR" + +set "chars=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" +set "random_str=" + +for /l %%i in (1,1,!len!) do ( + set /a rand_index=!random! %% 62 + call set "char=%%chars:~!rand_index!,1%%" + set "random_str=!random_str!!char!" +) + +endlocal & set "%varname%=%random_str%" +exit /b 0 + +:Start +setlocal +set DESCRIPTION=%1 +set SCRIPT_PATH=%2 +set SCRIPT_FILE=%3 + +set PARAMS= +shift /3 +:params_loop +if not "%~1"=="" ( + set "PARAMS=%PARAMS% %~3" + shift + goto params_loop +) + +if exist "%SCRIPT_PATH%\%SCRIPT_FILE%" ( + echo. + call :log_info Starting %DESCRIPTION%... + cd /d "%SCRIPT_PATH%" + start "%DESCRIPTION% Startup" /B cmd /c "%SCRIPT_FILE% %PARAMS%" + if errorlevel 1 ( + call :log_error %DESCRIPTION% start Failed. + pause && exit /b 1 + ) +) else ( + call :log_error Script file not found: %SCRIPT_PATH%\%SCRIPT_FILE% + pause && exit /b 1 +) +endlocal +exit /b 0 + +:GetFormattedTime +for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "datetime=%%a" +set "FormattedTime=%datetime:~0,4%-%datetime:~4,2%-%datetime:~6,2% %datetime:~8,2%:%datetime:~10,2%:%datetime:~12,2%" +exit /b 0 + +:GetDate +for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "datetime=%%a" +set "FormattedDate=%datetime:~0,4%%datetime:~4,2%%datetime:~6,2%" +exit /b 0 + :main setlocal + +:: nginx call :GetUsageNumberOfPidsByPort 18080 if !ERRORLEVEL! neq 0 ( call :log_info Found !ERRORLEVEL! processes. @@ -225,14 +275,28 @@ if !ERRORLEVEL! neq 0 ( timeout /t 1 /nobreak >nul call :Start "Nginx" "%SCRIPT_DIR%nginx" "home-web.exe" "-c" "conf/web.conf" + +:: redis timeout /t 3 /nobreak >nul call :Start "Redis" "%SCRIPT_DIR%redis" "redis-server.exe" "redis.conf" + +:: minio timeout /t 3 /nobreak >nul call :Start "MinIO" "%SCRIPT_DIR%io" "minio-server.bat" + +:: rocketmq timeout /t 3 /nobreak >nul call :Start "RocketMQ" "%SCRIPT_DIR%rocketmq\sbin" "rocketmq.bat" +set PORT_LIST=9876:RocketMQ-NameServer 10911:RocketMQ-Broker 8081:RocketMQ-Proxy 8088:RocketMQ-Dashboard +set SERVER_HUMP=RocketMQ +set CHECK_INTERVAL=5 +set MAX_WAIT=60 +set counter=0 +call :ListenPortList + + endlocal cmd /k \ No newline at end of file