This commit is contained in:
yuejiajun 2025-08-21 12:10:46 +08:00
parent 14412a9c35
commit a39b9e0598

View File

@ -44,7 +44,24 @@ if defined LOG_TITLE (
) )
exit /b 0 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 call :RandomStr 16 RAND_NAME
set TARGET_DIR=%temp%\!CURRENT_DATE! set TARGET_DIR=%temp%\!CURRENT_DATE!
if not exist "!TARGET_DIR!" mkdir "!TARGET_DIR!" if not exist "!TARGET_DIR!" mkdir "!TARGET_DIR!"
@ -80,65 +97,6 @@ del %single_pid_tmp%.txt
endlocal & set pid=%pid% endlocal & set pid=%pid%
exit /b 0 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 :GetUsageNumberOfPidsByPort
setlocal setlocal
set "PORT=%~1" set "PORT=%~1"
@ -209,9 +167,101 @@ del "!PID_LIST_FILE!" 2>nul
endlocal & exit /b %UNIQUE_COUNT% 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 :main
setlocal setlocal
:: nginx
call :GetUsageNumberOfPidsByPort 18080 call :GetUsageNumberOfPidsByPort 18080
if !ERRORLEVEL! neq 0 ( if !ERRORLEVEL! neq 0 (
call :log_info Found !ERRORLEVEL! processes. call :log_info Found !ERRORLEVEL! processes.
@ -225,14 +275,28 @@ if !ERRORLEVEL! neq 0 (
timeout /t 1 /nobreak >nul timeout /t 1 /nobreak >nul
call :Start "Nginx" "%SCRIPT_DIR%nginx" "home-web.exe" "-c" "conf/web.conf" call :Start "Nginx" "%SCRIPT_DIR%nginx" "home-web.exe" "-c" "conf/web.conf"
:: redis
timeout /t 3 /nobreak >nul timeout /t 3 /nobreak >nul
call :Start "Redis" "%SCRIPT_DIR%redis" "redis-server.exe" "redis.conf" call :Start "Redis" "%SCRIPT_DIR%redis" "redis-server.exe" "redis.conf"
:: minio
timeout /t 3 /nobreak >nul timeout /t 3 /nobreak >nul
call :Start "MinIO" "%SCRIPT_DIR%io" "minio-server.bat" call :Start "MinIO" "%SCRIPT_DIR%io" "minio-server.bat"
:: rocketmq
timeout /t 3 /nobreak >nul timeout /t 3 /nobreak >nul
call :Start "RocketMQ" "%SCRIPT_DIR%rocketmq\sbin" "rocketmq.bat" 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 endlocal
cmd /k cmd /k