128 lines
3.3 KiB
Batchfile
Raw Normal View History

2025-08-17 18:50:57 +08:00
@echo off
2025-08-20 19:42:11 +08:00
setlocal enabledelayedexpansion
chcp 65001 >nul
2025-08-17 18:50:57 +08:00
2025-08-20 19:42:11 +08:00
set SERVER_UPPER=MODEL
set SERVER_LOWER=model
set SERVER_HUMP=Model
set /a SERVER_PORT=28680
set /a WEBSITE_PORT=%SERVER_PORT%-10000
set modifyTitle=1
for %%a in (%*) do (
if /i "%%a"=="/notitle" set modifyTitle=0
)
if %modifyTitle% equ 1 (
title %SERVER_HUMP% Quick Start
)
:: =============================================
:: Validation
:: =============================================
if not defined !SERVER_UPPER!_MAIN (
echo [ERROR] !SERVER_UPPER!_MAIN environment variable is not defined
pause && exit /b 1
)
if not defined !SERVER_UPPER!_MANAGE_BIN (
echo [ERROR] !SERVER_UPPER!_MANAGE_BIN environment variable is not defined
pause && exit /b 1
)
if not defined !SERVER_UPPER!_VM_PARAMS (
echo Warning: !SERVER_UPPER!_VM_PARAMS environment variable is not defined
set %SERVER_UPPER%_VM_PARAMS=-Xms512m -Xmx2048m
)
cd /d "!%SERVER_UPPER%_MAIN!" 2>nul
if errorlevel 1 (
echo [ERROR] Directory not found: !%SERVER_UPPER%_MAIN!
echo Please verify %SERVER_UPPER%_MAIN environment variable
pause && exit /b 1
)
if not exist "!%SERVER_UPPER%_MANAGE_BIN!" (
echo [ERROR] Main JAR file not found: !%SERVER_UPPER%_MANAGE_BIN!
echo Please verify %SERVER_UPPER%_MANAGE_BIN environment variable
pause && exit /b 1
)
cd web 2>nul
if errorlevel 1 (
echo [ERROR] web directory does not exist in !%SERVER_UPPER%_MAIN!
pause && exit /b 1
)
if not exist "%SERVER_LOWER%-web.exe" (
echo [ERROR] %SERVER_LOWER%-web.exe does not exist in !%SERVER_UPPER%_MAIN!\web
pause && exit /b 1
)
if not exist "conf\web.conf" (
echo [ERROR] conf\web.conf does not exist in !%SERVER_UPPER%_MAIN!\web
pause && exit /b 1
)
:: =============================================
:: Service Launch
:: =============================================
cd ..
setlocal
echo Starting %SERVER_HUMP% Server...
jps -v | grep "\-Dserver.port=%SERVER_PORT%" | awk "{print $1}" >server.tmp
set /p pid=<server.tmp
del /f /q server.tmp 2>nul
if defined pid (
taskkill -f -pid !pid!
)
start "%SERVER_HUMP% Server" /B cmd /c "chcp 65001 && java !%SERVER_UPPER%_VM_PARAMS! -jar !%SERVER_UPPER%_MANAGE_BIN!"
echo Starting %SERVER_HUMP% Website...
cd web
taskkill -f -im %SERVER_LOWER%-web.exe >nul
start "%SERVER_HUMP% Website" /B cmd /c "%SERVER_LOWER%-web.exe -c conf\web.conf"
set MAX_WAIT=300
set CHECK_INTERVAL=5
set counter=0
echo Waiting for services to start...
echo.
:CHECK_LOOP
netstat -an | find ":%SERVER_PORT%" > nul
set server_up=%errorlevel%
netstat -an | find ":%WEBSITE_PORT%" > nul
set website_up=%errorlevel%
if !server_up! equ 0 if !website_up! equ 0 (
call :DISPLAY_SUCCESS
exit /b 0
2025-08-17 18:50:57 +08:00
)
2025-08-20 19:42:11 +08:00
set /a counter+=CHECK_INTERVAL
if !counter! geq %MAX_WAIT% (
echo Error: Services did not start within !counter! seconds
exit /b 1
2025-08-17 18:50:57 +08:00
)
2025-08-20 19:42:11 +08:00
timeout /t %CHECK_INTERVAL% /nobreak > nul
goto CHECK_LOOP
2025-08-17 18:50:57 +08:00
2025-08-20 19:42:11 +08:00
:DISPLAY_SUCCESS
:: =============================================
:: Status Display
:: =============================================
echo.
echo ========================================
echo %SERVER_HUMP% Services Successfully Started
echo ========================================
echo - %SERVER_HUMP% Server (Port: %SERVER_PORT%)
echo - %SERVER_HUMP% Website (Port: %WEBSITE_PORT%)
echo ========================================
echo.
endlocal
exit /b 0