Update ry.bat script
This commit is contained in:
64
assets/implementation/scripts/test_ry_bat.ps1
Normal file
64
assets/implementation/scripts/test_ry_bat.ps1
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
$ErrorActionPreference = 'Stop'
|
||||||
|
|
||||||
|
$repoRoot = Resolve-Path (Join-Path $PSScriptRoot '..\..\..')
|
||||||
|
$expectedJar = Join-Path $repoRoot 'ruoyi-admin\target\ruoyi-admin.jar'
|
||||||
|
$originalJar = Join-Path $repoRoot 'ruoyi-admin\target\ruoyi-admin.jar.original'
|
||||||
|
$backupOriginalJar = "$originalJar.codex-test-backup"
|
||||||
|
|
||||||
|
Push-Location $repoRoot
|
||||||
|
try {
|
||||||
|
$output = cmd /c "set RY_DRY_RUN=1&& call ry.bat start" 2>&1 | Out-String
|
||||||
|
$exitCode = $LASTEXITCODE
|
||||||
|
|
||||||
|
if ($exitCode -ne 0) {
|
||||||
|
throw "ry.bat dry-run failed with exit code $exitCode.`n$output"
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($output -notmatch 'START_CMD=java ') {
|
||||||
|
throw "Expected START_CMD output was not found.`n$output"
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($output -notmatch [regex]::Escape($expectedJar)) {
|
||||||
|
throw "Expected jar path was not found in dry-run output.`n$output"
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($unsupportedToken in @('PrintGCDateStamps', 'UseParallelOldGC', 'javaw')) {
|
||||||
|
if ($output -match [regex]::Escape($unsupportedToken)) {
|
||||||
|
throw "Unexpected token [$unsupportedToken] found in dry-run output.`n$output"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Test-Path $originalJar) {
|
||||||
|
Move-Item -Path $originalJar -Destination $backupOriginalJar -Force
|
||||||
|
try {
|
||||||
|
$packageOutput = cmd /c "set RY_DRY_RUN=1&& call ry.bat start" 2>&1 | Out-String
|
||||||
|
$packageExitCode = $LASTEXITCODE
|
||||||
|
|
||||||
|
if ($packageExitCode -ne 0) {
|
||||||
|
throw "ry.bat package dry-run failed with exit code $packageExitCode.`n$packageOutput"
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($packageOutput -notmatch 'BUILD_CMD=mvn -pl ruoyi-admin -am package -DskipTests') {
|
||||||
|
throw "Expected BUILD_CMD output was not found.`n$packageOutput"
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($packageOutput -notmatch [regex]::Escape($expectedJar)) {
|
||||||
|
throw "Expected jar path was not found in package dry-run output.`n$packageOutput"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
if (Test-Path $backupOriginalJar) {
|
||||||
|
Move-Item -Path $backupOriginalJar -Destination $originalJar -Force
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Host 'ry.bat dry-run verification passed.'
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
if (Test-Path $backupOriginalJar) {
|
||||||
|
Move-Item -Path $backupOriginalJar -Destination $originalJar -Force
|
||||||
|
}
|
||||||
|
|
||||||
|
Pop-Location
|
||||||
|
}
|
||||||
184
ry.bat
184
ry.bat
@@ -1,67 +1,147 @@
|
|||||||
@echo off
|
@echo off
|
||||||
|
setlocal EnableExtensions EnableDelayedExpansion
|
||||||
|
cd ../ruoyi-admin/target
|
||||||
|
|
||||||
rem jar平级目录
|
set "SCRIPT_DIR=%~dp0"
|
||||||
set AppName=ruoyi-admin.jar
|
if "%SCRIPT_DIR:~-1%"=="\" set "SCRIPT_DIR=%SCRIPT_DIR:~0,-1%"
|
||||||
|
|
||||||
rem JVM参数
|
set "APP_NAME=ruoyi-admin.jar"
|
||||||
set JVM_OPTS="-Dname=%AppName% -Duser.timezone=Asia/Shanghai -Xms512m -Xmx1024m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=512m -XX:+HeapDumpOnOutOfMemoryError -XX:+PrintGCDateStamps -XX:+PrintGCDetails -XX:NewRatio=1 -XX:SurvivorRatio=30 -XX:+UseParallelGC -XX:+UseParallelOldGC"
|
set "JAVA_EXE=%JAVA_EXE%"
|
||||||
|
if not defined JAVA_EXE set "JAVA_EXE=java"
|
||||||
|
set "JPS_EXE=%JPS_EXE%"
|
||||||
|
if not defined JPS_EXE set "JPS_EXE=jps"
|
||||||
|
set "MVN_EXE=%MVN_EXE%"
|
||||||
|
if not defined MVN_EXE set "MVN_EXE=mvn"
|
||||||
|
set "MVN_ARGS=-pl ruoyi-admin -am package -DskipTests"
|
||||||
|
set "JVM_OPTS=-Dname=%APP_NAME% -Duser.timezone=Asia/Shanghai -Xms512m -Xmx1024m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=512m -XX:+HeapDumpOnOutOfMemoryError -XX:NewRatio=1 -XX:SurvivorRatio=30 -XX:+UseParallelGC"
|
||||||
|
set "DRY_RUN="
|
||||||
|
if /I "%RY_DRY_RUN%"=="1" set "DRY_RUN=1"
|
||||||
|
if /I "%~2"=="--dry-run" set "DRY_RUN=1"
|
||||||
|
|
||||||
|
if /I "%~1"=="start" goto start
|
||||||
|
if /I "%~1"=="stop" goto stop
|
||||||
|
if /I "%~1"=="restart" goto restart
|
||||||
|
if /I "%~1"=="status" goto status
|
||||||
|
if /I "%~1"=="help" goto help
|
||||||
|
if not "%~1"=="" goto help
|
||||||
|
|
||||||
|
:menu
|
||||||
ECHO.
|
ECHO.
|
||||||
ECHO. [1] 启动%AppName%
|
ECHO. [1] Start %APP_NAME%
|
||||||
ECHO. [2] 关闭%AppName%
|
ECHO. [2] Stop %APP_NAME%
|
||||||
ECHO. [3] 重启%AppName%
|
ECHO. [3] Restart %APP_NAME%
|
||||||
ECHO. [4] 启动状态 %AppName%
|
ECHO. [4] Status %APP_NAME%
|
||||||
ECHO. [5] 退 出
|
ECHO. [5] Exit
|
||||||
ECHO.
|
ECHO.
|
||||||
|
ECHO.Select an action:
|
||||||
ECHO.请输入选择项目的序号:
|
|
||||||
set /p ID=
|
set /p ID=
|
||||||
IF "%id%"=="1" GOTO start
|
if /I "%ID%"=="1" goto start
|
||||||
IF "%id%"=="2" GOTO stop
|
if /I "%ID%"=="2" goto stop
|
||||||
IF "%id%"=="3" GOTO restart
|
if /I "%ID%"=="3" goto restart
|
||||||
IF "%id%"=="4" GOTO status
|
if /I "%ID%"=="4" goto status
|
||||||
IF "%id%"=="5" EXIT
|
if /I "%ID%"=="5" exit /b 0
|
||||||
PAUSE
|
echo Invalid selection.
|
||||||
|
pause
|
||||||
|
goto menu
|
||||||
|
|
||||||
|
:help
|
||||||
|
echo Usage: ry.bat ^<start^|stop^|restart^|status^> [--dry-run]
|
||||||
|
exit /b 1
|
||||||
|
|
||||||
|
:resolveAppPath
|
||||||
|
set "APP_PATH=%SCRIPT_DIR%\%APP_NAME%"
|
||||||
|
if exist "%APP_PATH%" exit /b 0
|
||||||
|
set "APP_PATH=%SCRIPT_DIR%\ruoyi-admin\target\%APP_NAME%"
|
||||||
|
if exist "%APP_PATH%" exit /b 0
|
||||||
|
set "APP_PATH="
|
||||||
|
exit /b 1
|
||||||
|
|
||||||
|
:shouldPackageJar
|
||||||
|
set "NEED_PACKAGE="
|
||||||
|
if not exist "%SCRIPT_DIR%\pom.xml" exit /b 0
|
||||||
|
if not exist "%SCRIPT_DIR%\ruoyi-admin\pom.xml" exit /b 0
|
||||||
|
if exist "%SCRIPT_DIR%\ruoyi-admin\target\%APP_NAME%.original" exit /b 0
|
||||||
|
set "NEED_PACKAGE=1"
|
||||||
|
exit /b 0
|
||||||
|
|
||||||
|
:findProcess
|
||||||
|
set "pid="
|
||||||
|
set "image_name="
|
||||||
|
for /f "tokens=1,*" %%a in ('%JPS_EXE% -l ^| findstr /I /C:"%APP_NAME%"') do (
|
||||||
|
set "pid=%%a"
|
||||||
|
set "image_name=%%b"
|
||||||
|
goto findProcessDone
|
||||||
|
)
|
||||||
|
:findProcessDone
|
||||||
|
exit /b 0
|
||||||
|
|
||||||
:start
|
:start
|
||||||
for /f "usebackq tokens=1-2" %%a in (`jps -l ^| findstr %AppName%`) do (
|
call :shouldPackageJar
|
||||||
set pid=%%a
|
if defined NEED_PACKAGE (
|
||||||
set image_name=%%b
|
if defined DRY_RUN echo BUILD_CMD=%MVN_EXE% %MVN_ARGS%
|
||||||
)
|
if not defined DRY_RUN (
|
||||||
if defined pid (
|
echo Packaging executable jar for %APP_NAME%...
|
||||||
echo %%is running
|
pushd "%SCRIPT_DIR%"
|
||||||
PAUSE
|
call %MVN_EXE% %MVN_ARGS%
|
||||||
)
|
set "build_exit=!ERRORLEVEL!"
|
||||||
|
popd
|
||||||
|
if not "!build_exit!"=="0" exit /b !build_exit!
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
start javaw %JVM_OPTS% -jar %AppName%
|
call :resolveAppPath
|
||||||
|
if errorlevel 1 (
|
||||||
|
echo [ERROR] Unable to find %APP_NAME%.
|
||||||
|
echo Checked:
|
||||||
|
echo %SCRIPT_DIR%\%APP_NAME%
|
||||||
|
echo %SCRIPT_DIR%\ruoyi-admin\target\%APP_NAME%
|
||||||
|
exit /b 1
|
||||||
|
)
|
||||||
|
|
||||||
echo starting……
|
call :findProcess
|
||||||
echo Start %AppName% success...
|
if defined pid (
|
||||||
goto:eof
|
echo %APP_NAME% is already running. PID=!pid!
|
||||||
|
exit /b 0
|
||||||
|
)
|
||||||
|
|
||||||
|
if defined DRY_RUN (
|
||||||
|
echo START_CMD=%JAVA_EXE% %JVM_OPTS% -jar "%APP_PATH%"
|
||||||
|
exit /b 0
|
||||||
|
)
|
||||||
|
|
||||||
|
echo Starting %APP_NAME%...
|
||||||
|
%JAVA_EXE% %JVM_OPTS% -jar "%APP_PATH%"
|
||||||
|
exit /b %ERRORLEVEL%
|
||||||
|
|
||||||
rem 函数stop通过jps命令查找pid并结束进程
|
|
||||||
:stop
|
:stop
|
||||||
for /f "usebackq tokens=1-2" %%a in (`jps -l ^| findstr %AppName%`) do (
|
call :findProcess
|
||||||
set pid=%%a
|
if not defined pid (
|
||||||
set image_name=%%b
|
echo process %APP_NAME% does not exist
|
||||||
)
|
exit /b 0
|
||||||
if not defined pid (echo process %AppName% does not exists) else (
|
)
|
||||||
echo prepare to kill %image_name%
|
|
||||||
echo start kill %pid% ...
|
echo Stopping %APP_NAME% (PID !pid! )...
|
||||||
rem 根据进程ID,kill进程
|
taskkill /f /pid !pid! >nul 2>nul
|
||||||
taskkill /f /pid %pid%
|
if errorlevel 1 (
|
||||||
)
|
echo [ERROR] Failed to stop %APP_NAME%.
|
||||||
goto:eof
|
exit /b 1
|
||||||
|
)
|
||||||
|
|
||||||
|
echo %APP_NAME% stopped.
|
||||||
|
exit /b 0
|
||||||
|
|
||||||
:restart
|
:restart
|
||||||
call :stop
|
call :stop
|
||||||
call :start
|
if errorlevel 1 exit /b 1
|
||||||
goto:eof
|
call :start
|
||||||
|
exit /b %ERRORLEVEL%
|
||||||
|
|
||||||
:status
|
:status
|
||||||
for /f "usebackq tokens=1-2" %%a in (`jps -l ^| findstr %AppName%`) do (
|
call :findProcess
|
||||||
set pid=%%a
|
if not defined pid (
|
||||||
set image_name=%%b
|
echo process %APP_NAME% is dead
|
||||||
)
|
exit /b 0
|
||||||
if not defined pid (echo process %AppName% is dead ) else (
|
)
|
||||||
echo %image_name% is running
|
|
||||||
)
|
echo %image_name% is running with PID !pid!
|
||||||
goto:eof
|
exit /b 0
|
||||||
|
|||||||
Reference in New Issue
Block a user