-
-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: improve relevant scripts (#888)
- Loading branch information
Showing
8 changed files
with
298 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
@echo off | ||
setlocal EnableDelayedExpansion | ||
|
||
set "HOME=%CD%" | ||
if not defined JAVA_HOME set "JAVA_HOME=C:\Program Files\Java\jdk" | ||
set "APPLICATION_NAME=io.edurt.datacap.server.DataCap" | ||
set "APPLICATION_PID=" | ||
|
||
call :check_java_version | ||
call :job_before_echo_basic | ||
call :job_runner_checker_server | ||
call :job_runner_debug_server | ||
exit /b | ||
|
||
:check_java_version | ||
for /f "tokens=3" %%i in ('"%JAVA_HOME%\bin\java" -version 2^>^&1 ^| findstr "version"') do ( | ||
set java_version=%%i | ||
) | ||
set java_version=!java_version:"=! | ||
for /f "tokens=1 delims=." %%a in ("!java_version!") do set major_version=%%a | ||
if not "!major_version!"=="1" if not "!major_version!"=="11" ( | ||
echo Error: Java version [ !java_version! ] is not supported. Please use Java 1.8 or 11. | ||
exit /b 1 | ||
) | ||
exit /b 0 | ||
|
||
:get_jvm_conf | ||
for /f "tokens=* delims=" %%a in ('findstr /v "^#" "%HOME%\configure\jvm.conf"') do set "JVM_CONF=!JVM_CONF! %%a" | ||
exit /b | ||
|
||
:job_before_echo_basic | ||
echo. | ||
echo Job before echo basic | ||
echo ============================================ | ||
echo Runtime home ^| %HOME% | ||
echo Runtime java home ^| %JAVA_HOME% | ||
echo Runtime application name ^| %APPLICATION_NAME% | ||
echo ============================================ | ||
echo. | ||
exit /b | ||
|
||
:job_before_apply_server | ||
for /f "tokens=2" %%a in ('wmic process where "commandline like '%%%APPLICATION_NAME%%%'" get processid /format:value') do ( | ||
set "APPLICATION_PID=%%a" | ||
) | ||
exit /b | ||
|
||
:job_runner_checker_server | ||
echo. | ||
echo Job runner check server | ||
echo ============================================ | ||
call :job_before_apply_server | ||
echo Runtime process ^| %APPLICATION_PID% | ||
if "%APPLICATION_PID%"=="" ( | ||
echo Server status ^| stopped | ||
echo ============================================ | ||
echo. | ||
) else ( | ||
echo Server status ^| running | ||
echo ============================================ | ||
echo. | ||
exit 1 | ||
) | ||
exit /b | ||
|
||
:job_runner_debug_server | ||
echo. | ||
echo Job runner server | ||
echo ============================================ | ||
echo Server starting ^| %APPLICATION_NAME% | ||
cd /d "%HOME%" | ||
call :get_jvm_conf | ||
"%JAVA_HOME%\bin\java" -cp "%HOME%\lib\*" %JVM_CONF% "%APPLICATION_NAME%" --spring.config.location="%HOME%\configure\" | ||
exit /b |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
@echo off | ||
setlocal EnableDelayedExpansion | ||
set "HOME=%cd%" | ||
set "VERSION=2024.4.0" | ||
set "CDN_CENTER=https://repo1.maven.org/maven2/io/edurt/datacap" | ||
|
||
:: 检查并创建临时目录 | ||
:: Check and create temporary directory | ||
set "TEMP_DIR=%HOME%\temp" | ||
if not exist "%TEMP_DIR%" mkdir "%TEMP_DIR%" | ||
echo ========== Starting installation ========== | ||
echo Version: %VERSION% | ||
echo CDN Center: %CDN_CENTER% | ||
if not exist "%HOME%\plugins" ( | ||
mkdir "%HOME%\plugins" | ||
echo Created plugins directory | ||
) | ||
|
||
:: 使用更通用的下载方法 | ||
:: Use more universal download method | ||
set "DOWNLOAD_COMMAND=" | ||
where powershell >nul 2>nul | ||
if %errorlevel% equ 0 ( | ||
set "DOWNLOAD_COMMAND=powershell" | ||
) else ( | ||
where curl >nul 2>nul | ||
if %errorlevel% equ 0 ( | ||
set "DOWNLOAD_COMMAND=curl -L -o" | ||
) else ( | ||
where wget >nul 2>nul | ||
if %errorlevel% equ 0 ( | ||
set "DOWNLOAD_COMMAND=wget -O" | ||
) else ( | ||
echo Error: Neither PowerShell, curl, nor wget found. | ||
exit /b 1 | ||
) | ||
) | ||
) | ||
|
||
:: 使用更通用的解压方法 | ||
:: Use more universal unzip method | ||
set "UNZIP_COMMAND=" | ||
where tar >nul 2>nul | ||
if %errorlevel% equ 0 ( | ||
set "UNZIP_COMMAND=tar -xzf" | ||
) else ( | ||
where 7z >nul 2>nul | ||
if %errorlevel% equ 0 ( | ||
set "UNZIP_COMMAND=7z x" | ||
) else ( | ||
echo Error: Neither tar nor 7z found. | ||
exit /b 1 | ||
) | ||
) | ||
|
||
for /f "usebackq tokens=*" %%A in (`type "%HOME%\configure\plugin.conf"`) do ( | ||
set "line=%%A" | ||
if not "!line!"=="" if not "!line:~0,2!"=="--" ( | ||
set "DOWNLOAD_URL=%CDN_CENTER%/!line!/%VERSION%/!line!-%VERSION%-bin.tar.gz" | ||
set "TEMP_FILE=%TEMP_DIR%\!line!-%VERSION%-bin.tar.gz" | ||
|
||
echo Downloading: !line! | ||
if "!DOWNLOAD_COMMAND!"=="powershell" ( | ||
powershell -NoProfile -ExecutionPolicy Bypass -Command "$ProgressPreference = 'SilentlyContinue'; Invoke-WebRequest -Uri '!DOWNLOAD_URL!' -OutFile '!TEMP_FILE!'" | ||
) else ( | ||
%DOWNLOAD_COMMAND% "!TEMP_FILE!" "!DOWNLOAD_URL!" | ||
) | ||
if !errorlevel! equ 0 ( | ||
echo Extracting: !line! | ||
%UNZIP_COMMAND% "!TEMP_FILE!" -C "%HOME%\plugins" | ||
del "!TEMP_FILE!" | ||
) | ||
) | ||
) | ||
|
||
:: 清理临时目录 | ||
:: Clean up temporary directory | ||
rd /s /q "%TEMP_DIR%" 2>nul | ||
echo ========== Installation complete ========== | ||
endlocal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
@echo off | ||
set "HOME=%CD%" | ||
|
||
call "%HOME%\bin\shutdown.bat" | ||
call "%HOME%\bin\startup.bat" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
@echo off | ||
set "HOME=%CD%" | ||
set "APPLICATION_NAME=io.edurt.datacap.server.DataCap" | ||
set "APPLICATION_PID=" | ||
|
||
call :job_before_echo_basic | ||
call :job_runner_stop_server | ||
exit /b | ||
|
||
:job_before_echo_basic | ||
echo. | ||
echo Job before echo basic | ||
echo ============================================ | ||
echo Runtime home | %HOME% | ||
echo Runtime application name | %APPLICATION_NAME% | ||
echo ============================================ | ||
echo. | ||
exit /b | ||
|
||
:job_before_apply_server | ||
for /f "tokens=1" %%a in ('tasklist /fi "imagename eq java.exe" /v ^| findstr /i "%APPLICATION_NAME%"') do ( | ||
set "APPLICATION_PID=%%a" | ||
) | ||
exit /b | ||
|
||
:job_runner_stop_server | ||
echo. | ||
echo Job runner check server | ||
echo ============================================ | ||
call :job_before_apply_server | ||
echo Runtime process | %APPLICATION_PID% | ||
if "%APPLICATION_PID%"=="" ( | ||
echo Server status | stopped | ||
echo ============================================ | ||
echo. | ||
exit 1 | ||
) else ( | ||
echo Server stopping | %APPLICATION_NAME% | ||
taskkill /F /PID %APPLICATION_PID% | ||
if exist "%HOME%\pid" rd /s /q "%HOME%\pid" | ||
echo Server stopped successfully | | ||
echo ============================================ | ||
echo. | ||
) | ||
exit /b |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
@echo off | ||
setlocal | ||
|
||
set "HOME=%CD%" | ||
if not defined JAVA_HOME set "JAVA_HOME=C:\Program Files\Java\jdk" | ||
set "APPLICATION_NAME=io.edurt.datacap.server.DataCap" | ||
set "APPLICATION_PID=" | ||
|
||
call :check_java_version | ||
call :job_before_echo_basic | ||
call :job_runner_checker_server | ||
call :job_runner_start_server | ||
exit /b | ||
|
||
:check_java_version | ||
for /f "tokens=3" %%i in ('"%JAVA_HOME%\bin\java" -version 2^>^&1 ^| findstr "version"') do ( | ||
set java_version=%%i | ||
) | ||
set java_version=%java_version:"=% | ||
for /f "tokens=1 delims=." %%a in ("%java_version%") do set major_version=%%a | ||
if not "%major_version%"=="1" if not "%major_version%"=="11" ( | ||
echo Error: Java version [ %java_version% ] is not supported. Please use Java 1.8 or 11. | ||
exit /b 1 | ||
) | ||
exit /b 0 | ||
|
||
:get_jvm_conf | ||
set "JVM_CONF=" | ||
for /f "tokens=* delims=" %%a in ('findstr /v "^#" "%HOME%\configure\jvm.conf"') do set "JVM_CONF=%JVM_CONF% %%a" | ||
exit /b | ||
|
||
:job_before_echo_basic | ||
echo. | ||
echo Job before echo basic | ||
echo ============================================ | ||
echo Runtime home | %HOME% | ||
echo Runtime java home | %JAVA_HOME% | ||
echo Runtime application name | %APPLICATION_NAME% | ||
echo ============================================ | ||
echo. | ||
exit /b | ||
|
||
:job_before_apply_server | ||
for /f "tokens=1" %%a in ('tasklist /fi "imagename eq java.exe" /v ^| findstr /i "%APPLICATION_NAME%"') do ( | ||
set "APPLICATION_PID=%%a" | ||
) | ||
exit /b | ||
|
||
:job_runner_checker_server | ||
echo. | ||
echo Job runner check server | ||
echo ============================================ | ||
call :job_before_apply_server | ||
echo Runtime process | %APPLICATION_PID% | ||
if "%APPLICATION_PID%"=="" ( | ||
echo Server status | stopped | ||
echo ============================================ | ||
echo. | ||
) else ( | ||
echo Server status | running | ||
echo ============================================ | ||
echo. | ||
exit 1 | ||
) | ||
exit /b | ||
|
||
:job_runner_start_server | ||
echo. | ||
echo Job runner server | ||
echo ============================================ | ||
echo Server starting | %APPLICATION_NAME% | ||
cd /d "%HOME%" | ||
call :get_jvm_conf | ||
start /B "" "%JAVA_HOME%\bin\javaw" -cp "%HOME%\lib\*" %JVM_CONF% "%APPLICATION_NAME%" --spring.config.location="%HOME%\configure\" > nul 2>&1 | ||
timeout /t 5 > nul | ||
call :job_before_apply_server | ||
if "%APPLICATION_PID%"=="" ( | ||
echo Server start failed | | ||
) else ( | ||
echo %APPLICATION_PID% > pid | ||
echo Server start successful | | ||
) | ||
echo ============================================ | ||
echo. | ||
exit /b |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters