Compare commits
8 Commits
a39b9e0598
...
25bde28b29
Author | SHA1 | Date | |
---|---|---|---|
![]() |
25bde28b29 | ||
![]() |
0de4810365 | ||
![]() |
4c2f0ca473 | ||
![]() |
f44c976db8 | ||
![]() |
d8b12f9c6d | ||
![]() |
18b1103c90 | ||
![]() |
528f28c5b0 | ||
![]() |
871162f265 |
453
base/Resources/mysql/initialize.bat
Normal file
453
base/Resources/mysql/initialize.bat
Normal file
@ -0,0 +1,453 @@
|
||||
@echo off
|
||||
chcp 65001 >nul
|
||||
setlocal enabledelayedexpansion
|
||||
|
||||
:: version: 0.13
|
||||
|
||||
:: ===================================================================== 主逻辑顺序
|
||||
|
||||
:: 初始化脚本.
|
||||
call :INITIALIZE
|
||||
:: 调用主函数.
|
||||
goto :main >nul
|
||||
exit /b 0
|
||||
|
||||
:INITIALIZE
|
||||
set "SCRIPT_PATH=%~dp0"
|
||||
set "SCRIPT_NAME=%~nx0"
|
||||
set "SCRIPT_NAME_WITHOUT_EXT=%~n0"
|
||||
set "LOG_LEVEL_THRESHOLD=DEBUG"
|
||||
|
||||
call :get_current_time
|
||||
set "CALL_TIME=!CURRENT_TIME!"
|
||||
call :LOG_INFO "Startup %SCRIPT_NAME%: %CALL_TIME%"
|
||||
|
||||
set "SHOW_TITLE=true"
|
||||
for %%a in (%*) do (if /i "%%a"=="/notitle" set set "SHOW_TITLE=false")
|
||||
if "!SHOW_TITLE!"=="true" (title %SCRIPT_NAME%)
|
||||
|
||||
exit /b 0
|
||||
|
||||
:CHECK_IS_ADMIN
|
||||
net session >nul 2>&1
|
||||
if %errorLevel% neq 0 (
|
||||
exit /b 1
|
||||
)
|
||||
exit /b 0
|
||||
|
||||
:MD52String
|
||||
setlocal
|
||||
set "input=%~1"
|
||||
for /f "delims=" %%i in ('
|
||||
powershell -Command "[System.BitConverter]::ToString((New-Object -TypeName System.Security.Cryptography.MD5CryptoServiceProvider).ComputeHash([System.Text.Encoding]::UTF8.GetBytes('!input!'))).Replace('-','').ToLower()"
|
||||
') do set "md5=%%i"
|
||||
endlocal & set "md5=%md5%"
|
||||
exit /b 0
|
||||
|
||||
:MD5Hash2File
|
||||
setlocal
|
||||
set "input_text=%~1"
|
||||
set "return_var=%~2"
|
||||
where md5sum >nul 2>nul
|
||||
if errorlevel 1 (
|
||||
echo Error: md5sum command not found in PATH
|
||||
endlocal
|
||||
exit /b 1
|
||||
)
|
||||
set "temp_file=%TEMP%\md5_%RANDOM%.txt"
|
||||
echo !input_text! > "!temp_file!"
|
||||
for /f "tokens=1" %%i in ('md5sum "!temp_file!" 2^>nul') do (
|
||||
set "hash_result=%%i"
|
||||
)
|
||||
if "!hash_result!"=="" (
|
||||
echo Error: Failed to calculate MD5 hash
|
||||
del "!temp_file!" 2>nul
|
||||
endlocal
|
||||
exit /b 2
|
||||
)
|
||||
del "!temp_file!" 2>nul
|
||||
endlocal & set "%return_var%=%hash_result%"
|
||||
exit /b 0
|
||||
|
||||
:GET_TIME_STAMP
|
||||
setLocal
|
||||
set "level=%~1"
|
||||
if /i "%level%"=="ms" (
|
||||
for /f %%i in ('powershell -command "[math]::Truncate([decimal]((Get-Date).ToUniversalTime() - [datetime]'1970-01-01').TotalMilliseconds)"') do set timestamp_ms=%%i
|
||||
if %errorlevel% == 0 (
|
||||
set "timestamp=!timestamp_ms!"
|
||||
)
|
||||
)
|
||||
if /i "%level%"=="s" (
|
||||
for /f %%i in ('powershell -command "[math]::Truncate([decimal]((Get-Date).ToUniversalTime() - [datetime]'1970-01-01').TotalSeconds)"') do set timestamp_s=%%i
|
||||
if %errorlevel% == 0 (
|
||||
set "timestamp=!timestamp_s!"
|
||||
)
|
||||
)
|
||||
endLocal & set "timestamp=%timestamp%"
|
||||
exit /b 0
|
||||
|
||||
:GET_DATE_TIME
|
||||
for /f "tokens=2-4 delims=/ " %%a in ('date /t') do (set __date=%%a-%%b-%%c)
|
||||
for /f "tokens=1-2 delims=/:" %%a in ('time /t') do (set __time=%%a%%b)
|
||||
set "CURRENT_DATE_TIME=%__date%_%__time%"
|
||||
exit /b 0
|
||||
|
||||
:GET_CURRENT_TIME
|
||||
for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "datetime=%%a"
|
||||
set "CURRENT_TIME=%datetime:~0,4%-%datetime:~4,2%-%datetime:~6,2% %datetime:~8,2%:%datetime:~10,2%:%datetime:~12,2%"
|
||||
exit /b 0
|
||||
|
||||
:GET_CURRENT_DATE
|
||||
for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "datetime=%%a"
|
||||
set "CURRENT_DATE=%datetime:~0,4%%datetime:~4,2%%datetime:~6,2%"
|
||||
exit /b 0
|
||||
|
||||
:WAIT
|
||||
set /a "SECOND=%~1"
|
||||
timeout /t %SECOND% /nobreak >nul
|
||||
exit /b 0
|
||||
|
||||
:LOG
|
||||
setLocal
|
||||
set "LOG_LEVEL=%~1"
|
||||
set LOG_MESSAGE=
|
||||
shift
|
||||
:log__params_loop
|
||||
if not "%~1"=="" (
|
||||
set "LOG_MESSAGE=%LOG_MESSAGE% %~1"
|
||||
shift
|
||||
goto log__params_loop
|
||||
)
|
||||
call :get_log_level_num "%LOG_LEVEL%" "CALLER_LEVEL_NUM"
|
||||
call :get_log_level_num "%LOG_LEVEL_THRESHOLD%" "THRESHOLD_LEVEL_NUM"
|
||||
if %CALLER_LEVEL_NUM% lss %THRESHOLD_LEVEL_NUM% (
|
||||
endLocal
|
||||
exit /b 0
|
||||
)
|
||||
call :GET_CURRENT_TIME
|
||||
if /i "%LOG_LEVEL%"=="GROUP" echo.
|
||||
echo [%CURRENT_TIME%] - [%LOG_LEVEL%] - %LOG_MESSAGE%
|
||||
endLocal
|
||||
exit /b 0
|
||||
:get_log_level_num
|
||||
setLocal
|
||||
set "level=%~1"
|
||||
set "num=0"
|
||||
if /i "%level%"=="TRACE" set "num=1"
|
||||
if /i "%level%"=="DEBUG" set "num=2"
|
||||
if /i "%level%"=="INFO" set "num=3"
|
||||
if /i "%level%"=="WARN" set "num=4"
|
||||
if /i "%level%"=="GROUP" set "num=5"
|
||||
if /i "%level%"=="ERROR" set "num=6"
|
||||
endLocal & set "%~2=%num%"
|
||||
exit /b 0
|
||||
|
||||
:LOG_ERROR
|
||||
call :LOG ERROR %* && exit /b 0
|
||||
|
||||
:LOG_GROUP
|
||||
call :LOG GROUP "===============================" %* "==============================="
|
||||
exit /b 0
|
||||
|
||||
:LOG_WARN
|
||||
call :LOG WARN %* && exit /b 0
|
||||
|
||||
:LOG_INFO
|
||||
call :LOG INFO %* && exit /b 0
|
||||
|
||||
:LOG_DEBUG
|
||||
call :LOG DEBUG %* && exit /b 0
|
||||
|
||||
:LOG_DEBUG
|
||||
call :LOG DEBUG %* && exit /b 0
|
||||
|
||||
:LOG_TRACE
|
||||
call :LOG TRACE %* && exit /b 0
|
||||
|
||||
:GET_STRING_LENGTH
|
||||
setlocal
|
||||
set "input_str=%~1"
|
||||
set "str_length=%~2"
|
||||
:get_string_length_loop
|
||||
if defined input_str (
|
||||
set /a str_length+=1
|
||||
set "input_str=!input_str:~1!"
|
||||
goto get_string_length_loop
|
||||
)
|
||||
endlocal & (
|
||||
if not "%~2"=="" (
|
||||
set "%~2=%str_length%"
|
||||
) else (
|
||||
exit /b %str_length%
|
||||
)
|
||||
)
|
||||
exit /b 0
|
||||
|
||||
:GET_STRING_LENGTH_WITHOUT_SPACES
|
||||
setlocal
|
||||
set "input_str=%~1"
|
||||
set "result_var=%~2"
|
||||
set "tmp_char=!input_str!"
|
||||
set /a str_length=0
|
||||
for %%p in ( 4096 2048 1024 512 256 128 64 32 16 8 4 2 1 ) do (
|
||||
if not "!tmp_char:~%%p!"=="" (
|
||||
set "tmp_char=!tmp_char:~%%p!"
|
||||
set /a str_length+=%%p
|
||||
)
|
||||
)
|
||||
if not "!tmp_char!"=="" set /a str_length+=1
|
||||
call :LOG_TRACE Length=%str_length% String=%input_str%
|
||||
endlocal & (
|
||||
if not "%~2"=="" (
|
||||
set "%~2=%str_length%"
|
||||
) else (
|
||||
exit /b %str_length%
|
||||
)
|
||||
)
|
||||
exit /b 0
|
||||
|
||||
:RANDOM_STR
|
||||
setlocal
|
||||
set "len=%~1"
|
||||
set "varname=%~2"
|
||||
if "!varname!"=="" set "varname=RAND_STR"
|
||||
set "chars=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
|
||||
set "random_str="
|
||||
call :GET_STRING_LENGTH "%chars%" "charts_length"
|
||||
for /l %%i in (1,1,!len!) do (
|
||||
set /a rand_index=!random! %% !charts_length!
|
||||
call set "char=%%chars:~!rand_index!,1%%"
|
||||
set "random_str=!random_str!!char!"
|
||||
)
|
||||
endlocal & set "%varname%=%random_str%"
|
||||
exit /b 0
|
||||
|
||||
:GET_SINGLE_PID_BY_PORT
|
||||
setlocal
|
||||
call :RandomStr single_pid_tmp
|
||||
call :LOG_INFO netstat -ano ^| grep -E ":%1 " ^| grep "LISTENING" ^| awk "{print $NF}" ^| head -n 1
|
||||
netstat -ano | grep -E ":%1 " | grep "LISTENING" | awk "{print $NF}" | head -n 1 > %single_pid_tmp%.txt
|
||||
set /p pid=<%single_pid_tmp%.txt
|
||||
call :LOG_INFO pid: %pid%
|
||||
del %single_pid_tmp%.txt
|
||||
endlocal & set pid=%pid%
|
||||
exit /b 0
|
||||
|
||||
:GET_USED_PID_BY_PORT
|
||||
setlocal
|
||||
set "PORT=%~1"
|
||||
set /a "UNIQUE_COUNT=0"
|
||||
|
||||
if "!PORT!"=="" (
|
||||
call :log_error ERROR: Port number required
|
||||
endlocal & exit /b 0
|
||||
)
|
||||
|
||||
set "TEMP_FILE=%TEMP%\port_%PORT%_%RANDOM%_%TIME::=_%.tmp"
|
||||
set "PID_LIST_FILE=%TEMP%\pids_%PORT%_%RANDOM%.tmp"
|
||||
|
||||
call :LOG_INFO Checking for processes using port !PORT!...
|
||||
netstat -ano | grep -E ":!PORT! " > "!TEMP_FILE!"
|
||||
|
||||
if !errorlevel! neq 0 (
|
||||
call :LOG_INFO No process found using port !PORT!
|
||||
del "!TEMP_FILE!" 2>nul
|
||||
endlocal & exit /b 0
|
||||
)
|
||||
|
||||
echo. > "!PID_LIST_FILE!"
|
||||
|
||||
echo.
|
||||
call :LOG_GROUP Processes using port !PORT!
|
||||
for /f "tokens=5" %%a in (!TEMP_FILE!) do (
|
||||
set "PID=%%a"
|
||||
:: grep -E "^^!PID! $" "!PID_LIST_FILE!" >nul
|
||||
findstr /x "!PID!" "!PID_LIST_FILE!" >nul
|
||||
if !errorlevel! neq 0 (
|
||||
echo !PID! >> "!PID_LIST_FILE!"
|
||||
set /a "UNIQUE_COUNT+=1"
|
||||
call :LOG_INFO [!UNIQUE_COUNT!] PID: !PID!
|
||||
set "PROCESS_NAME="
|
||||
set "SESSION_NAME="
|
||||
set "SESSION_NUM="
|
||||
set "MEM_USAGE="
|
||||
|
||||
for /f "tokens=1,2,3,4,5*" %%b in ('tasklist /fi "PID eq !PID!" /fo table ^| findstr /i "!PID!"') do (
|
||||
if not "%%b"=="=" if not "%%b"=="Image" (
|
||||
call :LOG_INFO "PROCESS_NAME=%%b"
|
||||
call :LOG_INFO "PID_VALUE=%%c"
|
||||
call :LOG_INFO "SESSION_NAME=%%d"
|
||||
call :LOG_INFO "SESSION_NUM=%%e"
|
||||
call :LOG_INFO "MEM_USAGE=%%f"
|
||||
)
|
||||
)
|
||||
|
||||
if not "!PROCESS_NAME!"=="" (
|
||||
call :LOG_INFO Process: !PROCESS_NAME!
|
||||
call :LOG_INFO Memory: !MEM_USAGE!
|
||||
)
|
||||
echo.
|
||||
)
|
||||
)
|
||||
|
||||
if !UNIQUE_COUNT! gtr 0 (
|
||||
call :LOG_GROUP PIDs using port !PORT!
|
||||
:: type "!PID_LIST_FILE!"
|
||||
call :LOG_INFO Total: !UNIQUE_COUNT! process
|
||||
)
|
||||
|
||||
del "!TEMP_FILE!" 2>nul
|
||||
del "!PID_LIST_FILE!" 2>nul
|
||||
|
||||
endlocal & exit /b %UNIQUE_COUNT%
|
||||
|
||||
|
||||
:LISTEN_PORT_LIST
|
||||
call :listen_port_list__default_set
|
||||
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_DEBUG "!service! Server (Port: %%a) isn't ready..."
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
if !all_ports_up! equ 1 (
|
||||
call :DISPLAY_SUCCESS && 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_DEBUG "Waiting for services... (!COUNTER!/%MAX_WAIT% seconds)"
|
||||
echo.
|
||||
call :WAIT %CHECK_INTERVAL%
|
||||
goto LISTEN_PORT_LIST
|
||||
:listen_port_list__default_set
|
||||
set CHECK_INTERVAL=5
|
||||
set MAX_WAIT=90
|
||||
set COUNTER=0
|
||||
exit /b 0
|
||||
|
||||
:DISPLAY_SUCCESS
|
||||
call :WAIT 3
|
||||
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
|
||||
|
||||
:AUTOSTART
|
||||
setlocal
|
||||
set DESCRIPTION=%~1
|
||||
set SCRIPT_PATH=%~2
|
||||
set SCRIPT_FILE=%~3
|
||||
|
||||
set PARAMS=
|
||||
shift /3
|
||||
:autostart__params_loop
|
||||
if not "%~1"=="" (
|
||||
set "PARAMS=%PARAMS% %~3"
|
||||
shift
|
||||
goto autostart__params_loop
|
||||
)
|
||||
|
||||
call :GET_STRING_LENGTH "%SCRIPT_PATH%" "len"
|
||||
set /a "last_pos=len-1"
|
||||
for /f "delims=" %%c in ("!SCRIPT_PATH:~%last_pos%,1!") do (
|
||||
if not "%%c"=="\" (
|
||||
set "SCRIPT_PATH=%SCRIPT_PATH%\"
|
||||
)
|
||||
)
|
||||
|
||||
call :START "%DESCRIPTION%" "%SCRIPT_PATH%" "%SCRIPT_FILE%" %PARAMS%
|
||||
exit /b 0
|
||||
|
||||
:START
|
||||
setlocal
|
||||
set DESCRIPTION=%~1
|
||||
set SCRIPT_PATH=%~2
|
||||
set SCRIPT_FILE=%~3
|
||||
|
||||
set PARAMS=
|
||||
shift /3
|
||||
:start__params_loop
|
||||
if not "%~1"=="" (
|
||||
set "PARAMS=%PARAMS% %~3"
|
||||
shift
|
||||
goto start__params_loop
|
||||
)
|
||||
|
||||
call :LOG_DEBUG "%SCRIPT_PATH%%SCRIPT_FILE%"
|
||||
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 Startup file not found: %SCRIPT_PATH%\%SCRIPT_FILE%
|
||||
pause && exit /b 1
|
||||
)
|
||||
endlocal
|
||||
exit /b 0
|
||||
|
||||
:Exit
|
||||
set "exit_code=%~1"
|
||||
set "error_msg=%~2"
|
||||
if "!exit_code!"=="" set "exit_code=0"
|
||||
if not "!error_msg!"=="" (
|
||||
call :LOG_ERROR An error occurred^(!exit_code!^): !error_msg!
|
||||
)
|
||||
call :Cleanup
|
||||
exit /b !exit_code!
|
||||
|
||||
:Cleanup
|
||||
call :LOG_INFO Cleaning up resources ...
|
||||
goto :EOF
|
||||
|
||||
|
||||
|
||||
:: ===================================================================== 主逻辑起点
|
||||
:: 主函数.
|
||||
:main
|
||||
setlocal
|
||||
call :LOG_INFO "脚本开始执行"
|
||||
|
||||
call :LOG_GROUP 检查权限
|
||||
call :CHECK_IS_ADMIN
|
||||
if %errorLevel% neq 0 (
|
||||
call :Exit "1" "请使用管理员身份运行此脚本!"
|
||||
pause
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
call :LOG_GROUP 系统库初始化
|
||||
cd "%SCRIPT_PATH%"
|
||||
call :LOG_INFO SCRIPT_PATH %SCRIPT_PATH%
|
||||
call :AUTOSTART MySQL初始化 %SCRIPT_PATH% initialize-and-start-mysql.bat
|
||||
call :WAIT 10
|
||||
|
||||
call :LOG_GROUP 基本库初始化
|
||||
call :AUTOSTART "MySQL默认库初始化" "%SCRIPT_PATH%" "import-data-into-mysql.bat"
|
||||
|
||||
endlocal
|
||||
goto :Exit 0
|
@ -110,5 +110,5 @@ echo Service name: %SERVICE_NAME%
|
||||
echo New root password: %NEW_ROOT_PASSWORD%
|
||||
echo my.ini path: %MY_INI_PATH%
|
||||
|
||||
pause
|
||||
exit /b 0
|
||||
endlocal
|
@ -1,302 +1,467 @@
|
||||
@echo off
|
||||
setlocal enabledelayedexpansion
|
||||
chcp 65001 >nul
|
||||
title Quick Start
|
||||
setlocal enabledelayedexpansion
|
||||
|
||||
set "SCRIPT_DIR=%~dp0"
|
||||
call :log_info SCRIPT_DIR=%SCRIPT_DIR%
|
||||
:: version: 0.13
|
||||
|
||||
cd /d "%SCRIPT_DIR%"
|
||||
:: ===================================================================== 主逻辑顺序
|
||||
|
||||
call :main
|
||||
pause && exit /b 0
|
||||
|
||||
:log_info
|
||||
call :GetFormattedTime
|
||||
if defined LOG_TITLE (
|
||||
echo.
|
||||
echo [%FormattedTime%] - [INFO] - ==================== %LOG_TITLE% ====================
|
||||
set "LOG_TITLE="
|
||||
) else (
|
||||
echo [%FormattedTime%] - [INFO] - %*
|
||||
)
|
||||
:: 初始化脚本.
|
||||
call :INITIALIZE
|
||||
:: 调用主函数.
|
||||
goto :main >nul
|
||||
exit /b 0
|
||||
|
||||
:log_warn
|
||||
call :GetFormattedTime
|
||||
if defined LOG_TITLE (
|
||||
echo.
|
||||
echo [%FormattedTime%] - [WARN] - ==================== %LOG_TITLE% ====================
|
||||
set "LOG_TITLE="
|
||||
) else (
|
||||
echo [%FormattedTime%] - [WARN] - %*
|
||||
)
|
||||
:INITIALIZE
|
||||
set "SCRIPT_PATH=%~dp0"
|
||||
set "SCRIPT_NAME=%~nx0"
|
||||
set "SCRIPT_NAME_WITHOUT_EXT=%~n0"
|
||||
set "LOG_LEVEL_THRESHOLD=DEBUG"
|
||||
|
||||
call :get_current_time
|
||||
set "CALL_TIME=!CURRENT_TIME!"
|
||||
call :LOG_INFO "Startup %SCRIPT_NAME%: %CALL_TIME%"
|
||||
|
||||
set "SHOW_TITLE=true"
|
||||
for %%a in (%*) do (if /i "%%a"=="/notitle" set set "SHOW_TITLE=false")
|
||||
if "!SHOW_TITLE!"=="true" (title %SCRIPT_NAME%)
|
||||
|
||||
exit /b 0
|
||||
|
||||
:log_error
|
||||
call :GetFormattedTime
|
||||
if defined LOG_TITLE (
|
||||
echo.
|
||||
echo [%FormattedTime%] - [ERROR] - ==================== %LOG_TITLE% ====================
|
||||
set "LOG_TITLE="
|
||||
) else (
|
||||
echo [%FormattedTime%] - [ERROR] - %*
|
||||
)
|
||||
exit /b 0
|
||||
|
||||
: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
|
||||
:CHECK_IS_ADMIN
|
||||
net session >nul 2>&1
|
||||
if %errorLevel% neq 0 (
|
||||
exit /b 1
|
||||
)
|
||||
)
|
||||
|
||||
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!"
|
||||
|
||||
call :log_info Creating encrypted archive...
|
||||
rar a -ep1 -hp"Password#!CURRENT_DATE!" "!TARGET_DIR!\!RAND_NAME!.rar" "!TEMP_SQL_DIR!\*" >nul
|
||||
|
||||
if %errorLevel% neq 0 (
|
||||
call :log_error Error: Failed to create encrypted archive
|
||||
pause && exit /b 1
|
||||
)
|
||||
|
||||
if not exist "%SCRIPT_PATH%/patch/!CURRENT_DATE!" mkdir "%SCRIPT_PATH%/patch/!CURRENT_DATE!"
|
||||
call :log_info TEMP_SQL_DIR: %TEMP_SQL_DIR%
|
||||
|
||||
mv !TEMP_SQL_DIR!/*.rar "%SCRIPT_PATH%/patch/!CURRENT_DATE!"
|
||||
rd /s /q "!TEMP_SQL_DIR!" 2>nul
|
||||
|
||||
call :log_info Encryption completed successfully!
|
||||
call :log_info Archive: !TARGET_DIR!\!RAND_NAME!.rar
|
||||
call :log_info Password: Password#!CURRENT_DATE!
|
||||
|
||||
exit /b 0
|
||||
|
||||
:GetSinglePidByPort
|
||||
:MD52String
|
||||
setlocal
|
||||
call :RandomStr single_pid_tmp
|
||||
call :log_info netstat -ano ^| grep -E ":%1 " ^| grep "LISTENING" ^| awk "{print $NF}" ^| head -n 1
|
||||
netstat -ano | grep -E ":%1 " | grep "LISTENING" | awk "{print $NF}" | head -n 1 > %single_pid_tmp%.txt
|
||||
set /p pid=<%single_pid_tmp%.txt
|
||||
call :log_info pid: %pid%
|
||||
del %single_pid_tmp%.txt
|
||||
endlocal & set pid=%pid%
|
||||
set "input=%~1"
|
||||
for /f "delims=" %%i in ('
|
||||
powershell -Command "[System.BitConverter]::ToString((New-Object -TypeName System.Security.Cryptography.MD5CryptoServiceProvider).ComputeHash([System.Text.Encoding]::UTF8.GetBytes('!input!'))).Replace('-','').ToLower()"
|
||||
') do set "md5=%%i"
|
||||
endlocal & set "md5=%md5%"
|
||||
exit /b 0
|
||||
|
||||
:GetUsageNumberOfPidsByPort
|
||||
:MD5Hash2File
|
||||
setlocal
|
||||
set "PORT=%~1"
|
||||
set /a "UNIQUE_COUNT=0"
|
||||
|
||||
if "!PORT!"=="" (
|
||||
call :log_error ERROR: Port number required
|
||||
endlocal & exit /b 0
|
||||
set "input_text=%~1"
|
||||
set "return_var=%~2"
|
||||
where md5sum >nul 2>nul
|
||||
if errorlevel 1 (
|
||||
echo Error: md5sum command not found in PATH
|
||||
endlocal
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
set "TEMP_FILE=%TEMP%\port_%PORT%_%RANDOM%_%TIME::=_%.tmp"
|
||||
set "PID_LIST_FILE=%TEMP%\pids_%PORT%_%RANDOM%.tmp"
|
||||
|
||||
call :log_info Checking for processes using port !PORT!...
|
||||
netstat -ano | grep -E ":!PORT! " > "!TEMP_FILE!"
|
||||
|
||||
if !errorlevel! neq 0 (
|
||||
call :log_info No process found using port !PORT!
|
||||
del "!TEMP_FILE!" 2>nul
|
||||
endlocal & exit /b 0
|
||||
set "temp_file=%TEMP%\md5_%RANDOM%.txt"
|
||||
echo !input_text! > "!temp_file!"
|
||||
for /f "tokens=1" %%i in ('md5sum "!temp_file!" 2^>nul') do (
|
||||
set "hash_result=%%i"
|
||||
)
|
||||
if "!hash_result!"=="" (
|
||||
echo Error: Failed to calculate MD5 hash
|
||||
del "!temp_file!" 2>nul
|
||||
endlocal
|
||||
exit /b 2
|
||||
)
|
||||
del "!temp_file!" 2>nul
|
||||
endlocal & set "%return_var%=%hash_result%"
|
||||
exit /b 0
|
||||
|
||||
echo. > "!PID_LIST_FILE!"
|
||||
:GET_TIME_STAMP
|
||||
setLocal
|
||||
set "level=%~1"
|
||||
if /i "%level%"=="ms" (
|
||||
for /f %%i in ('powershell -command "[math]::Truncate([decimal]((Get-Date).ToUniversalTime() - [datetime]'1970-01-01').TotalMilliseconds)"') do set timestamp_ms=%%i
|
||||
if %errorlevel% == 0 (
|
||||
set "timestamp=!timestamp_ms!"
|
||||
)
|
||||
)
|
||||
if /i "%level%"=="s" (
|
||||
for /f %%i in ('powershell -command "[math]::Truncate([decimal]((Get-Date).ToUniversalTime() - [datetime]'1970-01-01').TotalSeconds)"') do set timestamp_s=%%i
|
||||
if %errorlevel% == 0 (
|
||||
set "timestamp=!timestamp_s!"
|
||||
)
|
||||
)
|
||||
endLocal & set "timestamp=%timestamp%"
|
||||
exit /b 0
|
||||
|
||||
echo.
|
||||
set "LOG_TITLE=Processes using port !PORT!"
|
||||
call :log_info ignore
|
||||
for /f "tokens=5" %%a in (!TEMP_FILE!) do (
|
||||
set "PID=%%a"
|
||||
:: grep -E "^^!PID! $" "!PID_LIST_FILE!" >nul
|
||||
findstr /x "!PID!" "!PID_LIST_FILE!" >nul
|
||||
if !errorlevel! neq 0 (
|
||||
echo !PID! >> "!PID_LIST_FILE!"
|
||||
set /a "UNIQUE_COUNT+=1"
|
||||
call :log_info [!UNIQUE_COUNT!] PID: !PID!
|
||||
set "PROCESS_NAME="
|
||||
set "SESSION_NAME="
|
||||
set "SESSION_NUM="
|
||||
set "MEM_USAGE="
|
||||
:GET_DATE_TIME
|
||||
for /f "tokens=2-4 delims=/ " %%a in ('date /t') do (set __date=%%a-%%b-%%c)
|
||||
for /f "tokens=1-2 delims=/:" %%a in ('time /t') do (set __time=%%a%%b)
|
||||
set "CURRENT_DATE_TIME=%__date%_%__time%"
|
||||
exit /b 0
|
||||
|
||||
for /f "tokens=1,2,3,4,5*" %%b in ('tasklist /fi "PID eq !PID!" /fo table ^| findstr /i "!PID!"') do (
|
||||
if not "%%b"=="=" if not "%%b"=="Image" (
|
||||
call :log_info "PROCESS_NAME=%%b"
|
||||
call :log_info "PID_VALUE=%%c"
|
||||
call :log_info "SESSION_NAME=%%d"
|
||||
call :log_info "SESSION_NUM=%%e"
|
||||
call :log_info "MEM_USAGE=%%f"
|
||||
:GET_CURRENT_TIME
|
||||
for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "datetime=%%a"
|
||||
set "CURRENT_TIME=%datetime:~0,4%-%datetime:~4,2%-%datetime:~6,2% %datetime:~8,2%:%datetime:~10,2%:%datetime:~12,2%"
|
||||
exit /b 0
|
||||
|
||||
:GET_CURRENT_DATE
|
||||
for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "datetime=%%a"
|
||||
set "CURRENT_DATE=%datetime:~0,4%%datetime:~4,2%%datetime:~6,2%"
|
||||
exit /b 0
|
||||
|
||||
:WAIT
|
||||
set /a "SECOND=%~1"
|
||||
timeout /t %SECOND% /nobreak >nul
|
||||
exit /b 0
|
||||
|
||||
:LOG
|
||||
setLocal
|
||||
set "LOG_LEVEL=%~1"
|
||||
set LOG_MESSAGE=
|
||||
shift
|
||||
:log__params_loop
|
||||
if not "%~1"=="" (
|
||||
set "LOG_MESSAGE=%LOG_MESSAGE% %~1"
|
||||
shift
|
||||
goto log__params_loop
|
||||
)
|
||||
call :get_log_level_num "%LOG_LEVEL%" "CALLER_LEVEL_NUM"
|
||||
call :get_log_level_num "%LOG_LEVEL_THRESHOLD%" "THRESHOLD_LEVEL_NUM"
|
||||
if %CALLER_LEVEL_NUM% lss %THRESHOLD_LEVEL_NUM% (
|
||||
endLocal
|
||||
exit /b 0
|
||||
)
|
||||
call :GET_CURRENT_TIME
|
||||
if /i "%LOG_LEVEL%"=="GROUP" echo.
|
||||
echo [%CURRENT_TIME%] - [%LOG_LEVEL%] - %LOG_MESSAGE%
|
||||
endLocal
|
||||
exit /b 0
|
||||
:get_log_level_num
|
||||
setLocal
|
||||
set "level=%~1"
|
||||
set "num=0"
|
||||
if /i "%level%"=="TRACE" set "num=1"
|
||||
if /i "%level%"=="DEBUG" set "num=2"
|
||||
if /i "%level%"=="INFO" set "num=3"
|
||||
if /i "%level%"=="WARN" set "num=4"
|
||||
if /i "%level%"=="GROUP" set "num=5"
|
||||
if /i "%level%"=="ERROR" set "num=6"
|
||||
endLocal & set "%~2=%num%"
|
||||
exit /b 0
|
||||
|
||||
:LOG_ERROR
|
||||
call :LOG ERROR %* && exit /b 0
|
||||
|
||||
:LOG_GROUP
|
||||
call :LOG GROUP "===============================" %* "==============================="
|
||||
exit /b 0
|
||||
|
||||
:LOG_WARN
|
||||
call :LOG WARN %* && exit /b 0
|
||||
|
||||
:LOG_INFO
|
||||
call :LOG INFO %* && exit /b 0
|
||||
|
||||
:LOG_DEBUG
|
||||
call :LOG DEBUG %* && exit /b 0
|
||||
|
||||
:LOG_DEBUG
|
||||
call :LOG DEBUG %* && exit /b 0
|
||||
|
||||
:LOG_TRACE
|
||||
call :LOG TRACE %* && exit /b 0
|
||||
|
||||
:GET_STRING_LENGTH
|
||||
setlocal
|
||||
set "input_str=%~1"
|
||||
set "str_length=%~2"
|
||||
:get_string_length_loop
|
||||
if defined input_str (
|
||||
set /a str_length+=1
|
||||
set "input_str=!input_str:~1!"
|
||||
goto get_string_length_loop
|
||||
)
|
||||
endlocal & (
|
||||
if not "%~2"=="" (
|
||||
set "%~2=%str_length%"
|
||||
) else (
|
||||
exit /b %str_length%
|
||||
)
|
||||
)
|
||||
exit /b 0
|
||||
|
||||
:GET_STRING_LENGTH_WITHOUT_SPACES
|
||||
setlocal
|
||||
set "input_str=%~1"
|
||||
set "result_var=%~2"
|
||||
set "tmp_char=!input_str!"
|
||||
set /a str_length=0
|
||||
for %%p in ( 4096 2048 1024 512 256 128 64 32 16 8 4 2 1 ) do (
|
||||
if not "!tmp_char:~%%p!"=="" (
|
||||
set "tmp_char=!tmp_char:~%%p!"
|
||||
set /a str_length+=%%p
|
||||
)
|
||||
)
|
||||
if not "!tmp_char!"=="" set /a str_length+=1
|
||||
call :LOG_TRACE Length=%str_length% String=%input_str%
|
||||
endlocal & (
|
||||
if not "%~2"=="" (
|
||||
set "%~2=%str_length%"
|
||||
) else (
|
||||
exit /b %str_length%
|
||||
)
|
||||
)
|
||||
exit /b 0
|
||||
|
||||
:RANDOM_STR
|
||||
setlocal
|
||||
set "len=%~1"
|
||||
set "varname=%~2"
|
||||
if "!varname!"=="" set "varname=RAND_STR"
|
||||
set "chars=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
|
||||
set "random_str="
|
||||
call :GET_STRING_LENGTH "%chars%" "charts_length"
|
||||
for /l %%i in (1,1,!len!) do (
|
||||
set /a rand_index=!random! %% !charts_length!
|
||||
call set "char=%%chars:~!rand_index!,1%%"
|
||||
set "random_str=!random_str!!char!"
|
||||
)
|
||||
endlocal & set "%varname%=%random_str%"
|
||||
exit /b 0
|
||||
|
||||
:GET_SINGLE_PID_BY_PORT
|
||||
setlocal
|
||||
call :RandomStr single_pid_tmp
|
||||
call :LOG_INFO netstat -ano ^| grep -E ":%1 " ^| grep "LISTENING" ^| awk "{print $NF}" ^| head -n 1
|
||||
netstat -ano | grep -E ":%1 " | grep "LISTENING" | awk "{print $NF}" | head -n 1 > %single_pid_tmp%.txt
|
||||
set /p pid=<%single_pid_tmp%.txt
|
||||
call :LOG_INFO pid: %pid%
|
||||
del %single_pid_tmp%.txt
|
||||
endlocal & set pid=%pid%
|
||||
exit /b 0
|
||||
|
||||
:GET_USED_PID_BY_PORT
|
||||
setlocal
|
||||
set "PORT=%~1"
|
||||
set /a "UNIQUE_COUNT=0"
|
||||
|
||||
if "!PORT!"=="" (
|
||||
call :log_error ERROR: Port number required
|
||||
endlocal & exit /b 0
|
||||
)
|
||||
|
||||
set "TEMP_FILE=%TEMP%\port_%PORT%_%RANDOM%_%TIME::=_%.tmp"
|
||||
set "PID_LIST_FILE=%TEMP%\pids_%PORT%_%RANDOM%.tmp"
|
||||
|
||||
call :LOG_INFO Checking for processes using port !PORT!...
|
||||
netstat -ano | grep -E ":!PORT! " > "!TEMP_FILE!"
|
||||
|
||||
if !errorlevel! neq 0 (
|
||||
call :LOG_INFO No process found using port !PORT!
|
||||
del "!TEMP_FILE!" 2>nul
|
||||
endlocal & exit /b 0
|
||||
)
|
||||
|
||||
echo. > "!PID_LIST_FILE!"
|
||||
|
||||
echo.
|
||||
call :LOG_GROUP Processes using port !PORT!
|
||||
for /f "tokens=5" %%a in (!TEMP_FILE!) do (
|
||||
set "PID=%%a"
|
||||
:: grep -E "^^!PID! $" "!PID_LIST_FILE!" >nul
|
||||
findstr /x "!PID!" "!PID_LIST_FILE!" >nul
|
||||
if !errorlevel! neq 0 (
|
||||
echo !PID! >> "!PID_LIST_FILE!"
|
||||
set /a "UNIQUE_COUNT+=1"
|
||||
call :LOG_INFO [!UNIQUE_COUNT!] PID: !PID!
|
||||
set "PROCESS_NAME="
|
||||
set "SESSION_NAME="
|
||||
set "SESSION_NUM="
|
||||
set "MEM_USAGE="
|
||||
|
||||
for /f "tokens=1,2,3,4,5*" %%b in ('tasklist /fi "PID eq !PID!" /fo table ^| findstr /i "!PID!"') do (
|
||||
if not "%%b"=="=" if not "%%b"=="Image" (
|
||||
call :LOG_INFO "PROCESS_NAME=%%b"
|
||||
call :LOG_INFO "PID_VALUE=%%c"
|
||||
call :LOG_INFO "SESSION_NAME=%%d"
|
||||
call :LOG_INFO "SESSION_NUM=%%e"
|
||||
call :LOG_INFO "MEM_USAGE=%%f"
|
||||
)
|
||||
)
|
||||
|
||||
if not "!PROCESS_NAME!"=="" (
|
||||
call :LOG_INFO Process: !PROCESS_NAME!
|
||||
call :LOG_INFO Memory: !MEM_USAGE!
|
||||
)
|
||||
echo.
|
||||
)
|
||||
)
|
||||
|
||||
if not "!PROCESS_NAME!"=="" (
|
||||
call :log_info Process: !PROCESS_NAME!
|
||||
call :log_info Memory: !MEM_USAGE!
|
||||
if !UNIQUE_COUNT! gtr 0 (
|
||||
call :LOG_GROUP PIDs using port !PORT!
|
||||
:: type "!PID_LIST_FILE!"
|
||||
call :LOG_INFO Total: !UNIQUE_COUNT! process
|
||||
)
|
||||
echo.
|
||||
)
|
||||
)
|
||||
|
||||
if !UNIQUE_COUNT! gtr 0 (
|
||||
set "LOG_TITLE=PIDs using port !PORT!"
|
||||
call :log_info ignore
|
||||
:: type "!PID_LIST_FILE!"
|
||||
call :log_info Total: !UNIQUE_COUNT! process
|
||||
)
|
||||
|
||||
del "!TEMP_FILE!" 2>nul
|
||||
del "!PID_LIST_FILE!" 2>nul
|
||||
del "!TEMP_FILE!" 2>nul
|
||||
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..."
|
||||
:LISTEN_PORT_LIST
|
||||
call :listen_port_list__default_set
|
||||
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_DEBUG "!service! Server (Port: %%a) isn't ready..."
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
if !all_ports_up! equ 1 (
|
||||
call :DisplaySuccess
|
||||
exit /b 0
|
||||
)
|
||||
if !all_ports_up! equ 1 (
|
||||
call :DISPLAY_SUCCESS && 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
|
||||
)
|
||||
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%"
|
||||
call :LOG_DEBUG "Waiting for services... (!COUNTER!/%MAX_WAIT% seconds)"
|
||||
echo.
|
||||
call :WAIT %CHECK_INTERVAL%
|
||||
goto LISTEN_PORT_LIST
|
||||
:listen_port_list__default_set
|
||||
set CHECK_INTERVAL=5
|
||||
set MAX_WAIT=90
|
||||
set COUNTER=0
|
||||
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
|
||||
:DISPLAY_SUCCESS
|
||||
call :WAIT 3
|
||||
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
|
||||
|
||||
: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%"
|
||||
:AUTOSTART
|
||||
setlocal
|
||||
set DESCRIPTION=%~1
|
||||
set SCRIPT_PATH=%~2
|
||||
set SCRIPT_FILE=%~3
|
||||
|
||||
set PARAMS=
|
||||
shift /3
|
||||
:autostart__params_loop
|
||||
if not "%~1"=="" (
|
||||
set "PARAMS=%PARAMS% %~3"
|
||||
shift
|
||||
goto autostart__params_loop
|
||||
)
|
||||
|
||||
call :GET_STRING_LENGTH "%SCRIPT_PATH%" "len"
|
||||
set /a "last_pos=len-1"
|
||||
for /f "delims=" %%c in ("!SCRIPT_PATH:~%last_pos%,1!") do (
|
||||
if not "%%c"=="\" (
|
||||
set "SCRIPT_PATH=%SCRIPT_PATH%\"
|
||||
)
|
||||
)
|
||||
|
||||
call :START "%DESCRIPTION%" "%SCRIPT_PATH%" "%SCRIPT_FILE%" %PARAMS%
|
||||
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%"
|
||||
:START
|
||||
setlocal
|
||||
set DESCRIPTION=%~1
|
||||
set SCRIPT_PATH=%~2
|
||||
set SCRIPT_FILE=%~3
|
||||
|
||||
set PARAMS=
|
||||
shift /3
|
||||
:start__params_loop
|
||||
if not "%~1"=="" (
|
||||
set "PARAMS=%PARAMS% %~3"
|
||||
shift
|
||||
goto start__params_loop
|
||||
)
|
||||
|
||||
call :LOG_DEBUG "%SCRIPT_PATH%%SCRIPT_FILE%"
|
||||
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 Startup file not found: %SCRIPT_PATH%\%SCRIPT_FILE%
|
||||
pause && exit /b 1
|
||||
)
|
||||
endlocal
|
||||
exit /b 0
|
||||
|
||||
:Exit
|
||||
set "exit_code=%~1"
|
||||
set "error_msg=%~2"
|
||||
if "!exit_code!"=="" set "exit_code=0"
|
||||
if not "!error_msg!"=="" (
|
||||
call :LOG_ERROR An error occurred^(!exit_code!^): !error_msg!
|
||||
)
|
||||
call :Cleanup
|
||||
exit /b !exit_code!
|
||||
|
||||
:Cleanup
|
||||
call :LOG_INFO Cleaning up resources ...
|
||||
goto :EOF
|
||||
|
||||
|
||||
|
||||
:: ===================================================================== 主逻辑起点
|
||||
:: 主函数.
|
||||
:main
|
||||
setlocal
|
||||
call :LOG_INFO "脚本开始执行"
|
||||
|
||||
|
||||
:: nginx
|
||||
call :GetUsageNumberOfPidsByPort 18080
|
||||
call :GET_USED_PID_BY_PORT 18080
|
||||
if !ERRORLEVEL! neq 0 (
|
||||
call :log_info Found !ERRORLEVEL! processes.
|
||||
call :GetSinglePidByPort 18080
|
||||
set "LOG_TITLE=Killing Process !pid!"
|
||||
call :log_info ignore
|
||||
:: taskkill -f -pid !pid! >nul
|
||||
call :LOG_INFO Found !ERRORLEVEL! processes.
|
||||
call :GET_SINGLE_PID_BY_PORT 18080
|
||||
call :LOG_GROUP Killing Process !pid!
|
||||
taskkill -f -im home-web.exe
|
||||
)
|
||||
|
||||
timeout /t 1 /nobreak >nul
|
||||
call :Start "Nginx" "%SCRIPT_DIR%nginx" "home-web.exe" "-c" "conf/web.conf"
|
||||
call :AUTOSTART "Nginx" "%SCRIPT_PATH%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"
|
||||
call :AUTOSTART "Redis" "%SCRIPT_PATH%redis" "redis-server.exe" "redis.conf"
|
||||
|
||||
|
||||
:: minio
|
||||
timeout /t 3 /nobreak >nul
|
||||
call :Start "MinIO" "%SCRIPT_DIR%io" "minio-server.bat"
|
||||
call :AUTOSTART "MinIO" "%SCRIPT_PATH%io" "minio-server.bat"
|
||||
|
||||
|
||||
:: rocketmq
|
||||
timeout /t 3 /nobreak >nul
|
||||
call :Start "RocketMQ" "%SCRIPT_DIR%rocketmq\sbin" "rocketmq.bat"
|
||||
call :AUTOSTART "RocketMQ" "%SCRIPT_PATH%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
|
||||
|
||||
|
||||
call :LISTEN_PORT_LIST
|
||||
|
||||
endlocal
|
||||
cmd /k
|
||||
goto :Exit 0
|
||||
|
@ -72,16 +72,16 @@ if exist "%ROCKETMQ_HOME%\bin\rocketmq-dashboard.jar" (
|
||||
start "RocketMQ Dashboard" /B cmd /c ""%JAVA_HOME%\bin\java" -jar -Dserver.port=8088 "%ROCKETMQ_HOME%\bin\rocketmq-dashboard.jar""
|
||||
)
|
||||
|
||||
echo.
|
||||
echo ========================================
|
||||
echo RocketMQ Services Status
|
||||
echo ========================================
|
||||
echo - NameServer (Port: 9876)
|
||||
echo - Broker (Port: 10911)
|
||||
echo - Proxy (Port: 8081)
|
||||
echo - Dashboard (Port: 8080)
|
||||
echo ========================================
|
||||
echo.
|
||||
:: echo.
|
||||
:: echo ========================================
|
||||
:: echo RocketMQ Services Status
|
||||
:: echo ========================================
|
||||
:: echo - NameServer (Port: 9876)
|
||||
:: echo - Broker (Port: 10911)
|
||||
:: echo - Proxy (Port: 8081)
|
||||
:: echo - Dashboard (Port: 8080)
|
||||
:: echo ========================================
|
||||
:: echo.
|
||||
|
||||
exit /b 0
|
||||
|
||||
|
Binary file not shown.
@ -1,7 +1,7 @@
|
||||
;iss
|
||||
|
||||
#define MyAppName "基础环境"
|
||||
#define MyAppVersion "1.0.8"
|
||||
#define MyAppVersion "1.0.14"
|
||||
#define MyAppPublisher "X"
|
||||
#define MyAppURL "~"
|
||||
#define MyAppExeName "command"
|
||||
@ -54,7 +54,7 @@ PrivilegesRequired=admin
|
||||
ArchitecturesAllowed=x64compatible
|
||||
ArchitecturesInstallIn64BitMode=x64compatible
|
||||
OutputDir=Release\
|
||||
OutputBaseFilename=Setup-{#MyAppVersion}
|
||||
OutputBaseFilename=RuntimeSetup-{#MyAppVersion}
|
||||
|
||||
|
||||
; 语言选择
|
||||
@ -73,7 +73,7 @@ Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{
|
||||
;; 程序 ICO
|
||||
[Icons]
|
||||
;Name: "{autoprograms}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}.exe"
|
||||
Name: "{autodesktop}\Quick Start Environment"; Filename: "{app}\quick.bat"; Tasks: desktopicon
|
||||
Name: "{autodesktop}\Quick Start Environment"; Filename: "{app}\quick.bat"; Comment: "一键启动 Redis、MinIO、Home、RocketMQ 服务"; Tasks: desktopicon
|
||||
|
||||
|
||||
;; 组件安装方式
|
||||
@ -125,7 +125,7 @@ Name: "{app}\nginx\logs"; Permissions: users-modify; Components: Nginx;
|
||||
Name: "{app}\nginx\dist"; Permissions: users-modify; Components: Nginx;
|
||||
|
||||
|
||||
;; 安装前后删除文件
|
||||
;; 安装前后删除文件(存在不生效的可能,转为 code 实现)
|
||||
[InstallDelete]
|
||||
;Type: files; Name: "{app}\mysql\template.ini";
|
||||
;Type: files; Name: "{app}\mysql\template-initialize-and-start-mysql.bat";
|
||||
@ -164,36 +164,45 @@ Root: HKLM; Subkey: "SYSTEM\CurrentControlSet\Control\Session Manager\Environmen
|
||||
ValueName: "JAVA_HOME"; ValueData: "{app}\jdk"; Flags: uninsdeletevalue ;
|
||||
Root: HKLM; Subkey: "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"; ValueType: string; Components: JDK; \
|
||||
ValueName: "JDK_21"; ValueData: "{app}\jdk"; Flags: uninsdeletevalue ;
|
||||
; 为了启用 java、jps、jar 命令
|
||||
Root: HKLM; Subkey: "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"; ValueType: expandsz; Components: JDK; Flags: preservestringtype; AfterInstall: RefreshEnvironment; \
|
||||
ValueName: "Path"; ValueData: "{olddata};%JAVA_HOME%\bin"; Check: NeedsAddPath('%JAVA_HOME%\bin');
|
||||
|
||||
|
||||
|
||||
;; 【Redis】追加到 PATH 变量
|
||||
Root: HKLM; Subkey: "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"; ValueType: expandsz; Components: Redis; Flags: preservestringtype; AfterInstall: RefreshEnvironment; \
|
||||
ValueName: "Path"; ValueData: "{olddata};%X_COMMAND%\redis"; Check: NeedsAddPath('%X_COMMAND%\redis');
|
||||
|
||||
;; 【Redis】追加到 PATH 变量
|
||||
;Root: HKLM; Subkey: "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"; ValueType: expandsz; Components: Redis; Flags: preservestringtype; AfterInstall: RefreshEnvironment; \
|
||||
ValueName: "Path"; ValueData: "{olddata};%X_COMMAND%\redis"; Check: NeedsAddPath('%X_COMMAND%\redis');
|
||||
;
|
||||
; 关闭注册到环境变量,整体由一键启动脚本代为执行
|
||||
|
||||
|
||||
;; 【MinIO】追加到 PATH 变量
|
||||
Root: HKLM; Subkey: "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"; ValueType: expandsz; Components: MinIO; Flags: preservestringtype; AfterInstall: RefreshEnvironment; \
|
||||
;Root: HKLM; Subkey: "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"; ValueType: expandsz; Components: MinIO; Flags: preservestringtype; AfterInstall: RefreshEnvironment; \
|
||||
ValueName: "Path"; ValueData: "{olddata};%X_COMMAND%\io"; Check: NeedsAddPath('%X_COMMAND%\io');
|
||||
|
||||
;
|
||||
; 关闭注册到环境变量,整体由一键启动脚本代为执行
|
||||
|
||||
|
||||
;; 【Nginx】追加到 PATH 变量
|
||||
Root: HKLM; Subkey: "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"; ValueType: expandsz; Components: Nginx; Flags: preservestringtype; AfterInstall: RefreshEnvironment; \
|
||||
;Root: HKLM; Subkey: "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"; ValueType: expandsz; Components: Nginx; Flags: preservestringtype; AfterInstall: RefreshEnvironment; \
|
||||
ValueName: "Path"; ValueData: "{olddata};%X_COMMAND%\nginx"; Check: NeedsAddPath('%X_COMMAND%\nginx');
|
||||
|
||||
;
|
||||
; 关闭注册到环境变量,整体由一键启动脚本代为执行
|
||||
|
||||
|
||||
;; 【RocketMQ】追加到 PATH 变量
|
||||
; rocketmq 脚本必要参数
|
||||
Root: HKLM; Subkey: "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"; ValueType: string; Components: RocketMQ; Flags: uninsdeletevalue; \
|
||||
ValueName: "ROCKETMQ_HOME"; ValueData: "{app}\rocketmq"; Check: CheckRegistryPath('{app}\rocketmq');
|
||||
Root: HKLM; Subkey: "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"; ValueType: string; Components: RocketMQ; Flags: uninsdeletevalue; \
|
||||
;Root: HKLM; Subkey: "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"; ValueType: string; Components: RocketMQ; Flags: uninsdeletevalue; \
|
||||
ValueName: "ROCKETMQ_SBIN"; ValueData: "{app}\rocketmq\sbin";
|
||||
Root: HKLM; Subkey: "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"; ValueType: expandsz; Components: RocketMQ; Flags: preservestringtype; AfterInstall: RefreshEnvironment; \
|
||||
;Root: HKLM; Subkey: "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"; ValueType: expandsz; Components: RocketMQ; Flags: preservestringtype; AfterInstall: RefreshEnvironment; \
|
||||
ValueName: "Path"; ValueData: "{olddata};%ROCKETMQ_SBIN%"; Check: NeedsAddPath('%ROCKETMQ_SBIN%');
|
||||
;
|
||||
; 关闭注册到环境变量,整体由一键启动脚本代为执行
|
||||
|
||||
|
||||
|
||||
|
||||
@ -206,11 +215,15 @@ Root: HKLM; Subkey: "SYSTEM\CurrentControlSet\Control\Session Manager\Environmen
|
||||
ValueName: "X_MANAGE_DB_EXE"; ValueData: "{app}\mysql\bin\mysqld.exe";
|
||||
;Root: HKLM; Subkey: "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"; ValueType: string; Components: MySQL; Flags: uninsdeletevalue ; AfterInstall: RefreshEnvironment; \
|
||||
ValueName: "X_MANAGE_DB_COF"; ValueData: "{app}\mysql\my.ini";
|
||||
;
|
||||
; 暂时关闭注册到环境变量,暂时由 bat 启动或直接注册到服务
|
||||
; 上述环境变量是 ps1 启动时所需的必要参数,状态暂停,等待整理
|
||||
|
||||
|
||||
; MySQL【通用服务】,导入脚本数据使用
|
||||
Root: HKLM; Subkey: "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"; ValueType: string; Components: MySQL; Flags: uninsdeletevalue; \
|
||||
ValueName: "X_COMMAND_MYSQL"; ValueData: "{app}\mysql\";
|
||||
; 追加到 PATH 变量
|
||||
; 追加到 PATH 变量,where mysql 语法判定使用
|
||||
Root: HKLM; Subkey: "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"; ValueType: expandsz; Components: MySQL; Flags: preservestringtype; AfterInstall: RefreshEnvironment; \
|
||||
ValueName: "Path"; ValueData: "{olddata};%X_COMMAND_MYSQL%\bin"; Check: NeedsAddPath('%X_COMMAND_MYSQL%\bin');
|
||||
|
||||
@ -220,6 +233,7 @@ Root: HKLM; Subkey: "SYSTEM\CurrentControlSet\Control\Session Manager\Environmen
|
||||
[Code]
|
||||
|
||||
const
|
||||
// 系统环境变量
|
||||
WM_SETTINGCHANGE = 26; // 0x001A 的十进制
|
||||
SMTO_ABORTIFHUNG = 2; // 0x0002 的十进制
|
||||
|
||||
@ -227,6 +241,12 @@ const
|
||||
VC2019_REDIST_X64 = '{FF66E9F6-83E7-3A3E-AF14-8DE9A809A6A4}';
|
||||
VC2019_REDIST_X86 = '{422B21A3-06FA-3F2F-A6C6-21BCC9B8E2F3}';
|
||||
|
||||
// 服务
|
||||
SC_MANAGER_CONNECT = $0001;
|
||||
SERVICE_STOP = $0020;
|
||||
SERVICE_QUERY_STATUS = $0004;
|
||||
SERVICE_CONTROL_STOP = $00000001;
|
||||
|
||||
|
||||
// 获取安装密码
|
||||
function GetInstallPassword(): string;
|
||||
@ -243,6 +263,12 @@ begin
|
||||
end;
|
||||
|
||||
|
||||
// 导入 Windows API 函数,作用于 延迟函数
|
||||
function GetTickCount: DWord;
|
||||
external 'GetTickCount@kernel32.dll stdcall';
|
||||
|
||||
|
||||
// 导入 Windows API 函数,作用于 环境变量更新
|
||||
function SendMessageTimeout(
|
||||
hWnd: Integer;
|
||||
Msg: Integer;
|
||||
@ -255,6 +281,41 @@ function SendMessageTimeout(
|
||||
external 'SendMessageTimeoutW@user32.dll stdcall';
|
||||
|
||||
|
||||
// 导入必要的 Windows API 函数,作用于 服务
|
||||
function OpenService(
|
||||
hSCManager: Longword;
|
||||
lpServiceName: string;
|
||||
dwDesiredAccess: Longword
|
||||
): Longword;
|
||||
external 'OpenServiceW@advapi32.dll stdcall';
|
||||
|
||||
|
||||
// 导入必要的 Windows API 函数,作用于 服务
|
||||
function ControlService(
|
||||
hService: Longword;
|
||||
dwControl: Longword;
|
||||
var lpServiceStatus: Longword
|
||||
): Integer;
|
||||
external 'ControlService@advapi32.dll stdcall';
|
||||
|
||||
|
||||
// 导入必要的 Windows API 函数,作用于 服务
|
||||
function CloseServiceHandle(
|
||||
hSCObject: Longword
|
||||
): Integer;
|
||||
external 'CloseServiceHandle@advapi32.dll stdcall';
|
||||
|
||||
|
||||
// 导入必要的 Windows API 函数,作用于 服务
|
||||
function OpenSCManager(
|
||||
lpMachineName: string;
|
||||
lpDatabaseName: string;
|
||||
dwDesiredAccess: Longword
|
||||
): Longword;
|
||||
external 'OpenSCManagerW@advapi32.dll stdcall';
|
||||
|
||||
|
||||
|
||||
// 给 Path 系统环境变量追加环境
|
||||
function NeedsAddPath(Param: string): boolean;
|
||||
var
|
||||
@ -345,10 +406,37 @@ begin
|
||||
end;
|
||||
|
||||
|
||||
// 延迟n秒
|
||||
procedure Delay(Seconds: Integer);
|
||||
var
|
||||
ResultCode: Integer;
|
||||
begin
|
||||
Exec(ExpandConstant('{cmd}'), '/C timeout /t ' + IntToStr(Seconds) + ' /nobreak > nul', '', SW_HIDE, ewWaitUntilTerminated, ResultCode);
|
||||
end;
|
||||
|
||||
// 延迟n毫秒
|
||||
procedure DelayMS(MS: Cardinal);
|
||||
var
|
||||
T: Cardinal;
|
||||
begin
|
||||
T := GetTickCount;
|
||||
while (GetTickCount - T) < MS do
|
||||
begin
|
||||
// 处理消息队列,防止界面冻结
|
||||
Sleep(10);
|
||||
WizardForm.Refresh;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
|
||||
|
||||
// InitializeSetup 安装程序初始化时 检查系统环境、前置条件
|
||||
// InitializeWizard 向导初始化时 自定义界面、预设置
|
||||
// CurStepChanged 安装步骤改变时 在特定步骤(如安装前、后)执行自定义操作
|
||||
// DeinitializeSetup 安装结束时(无论成功与否) 清理临时文件、最终配置
|
||||
|
||||
|
||||
// 从模板创建配置文件
|
||||
procedure CreateConfigFromTemplate;
|
||||
var
|
||||
@ -367,7 +455,7 @@ var
|
||||
ReplaceCount: Integer;
|
||||
begin
|
||||
|
||||
// generate my.ini
|
||||
// 生成 my.ini
|
||||
TemplateIniPath := ExpandConstant('{app}\mysql\template.ini');
|
||||
TargetIniPath := ExpandConstant('{app}\mysql\my.ini');
|
||||
|
||||
@ -385,7 +473,7 @@ begin
|
||||
|
||||
|
||||
|
||||
// generate initialize-and-start-mysql.bat
|
||||
// 生成 initialize-and-start-mysql.bat
|
||||
TemplateInitialPath := ExpandConstant('{app}\mysql\template-initialize-and-start-mysql.bat');
|
||||
TargetInitialPath := ExpandConstant('{app}\mysql\initialize-and-start-mysql.bat');
|
||||
|
||||
@ -401,7 +489,7 @@ begin
|
||||
|
||||
|
||||
|
||||
// generate register-mysql-with-data.bat
|
||||
// 生成 register-mysql-with-data.bat
|
||||
TemplateRegisterPath := ExpandConstant('{app}\mysql\template-register-mysql-with-data.bat');
|
||||
TargetRegisterPath := ExpandConstant('{app}\mysql\register-mysql-with-data.bat');
|
||||
|
||||
@ -418,6 +506,141 @@ end;
|
||||
|
||||
|
||||
|
||||
// 删除过程文件
|
||||
procedure RemoveTempFile;
|
||||
begin
|
||||
// DeleteFile
|
||||
// DelTree
|
||||
|
||||
// 删除模版文件
|
||||
if FileExists(ExpandConstant('{app}\mysql\template.ini')) then
|
||||
DeleteFile(ExpandConstant('{app}\mysql\template.ini'));
|
||||
|
||||
if FileExists(ExpandConstant('{app}\mysql\template-initialize-and-start-mysql.bat')) then
|
||||
DelTree(ExpandConstant('{app}\mysql\template-initialize-and-start-mysql.bat'), False, True, False);
|
||||
|
||||
if FileExists(ExpandConstant('{app}\mysql\template-register-mysql-with-data.bat')) then
|
||||
DelTree(ExpandConstant('{app}\mysql\template-register-mysql-with-data.bat'), False, True, False);
|
||||
|
||||
if FileExists(ExpandConstant('{app}\mysql\import-data-into-mysql-v2.bat')) then
|
||||
DelTree(ExpandConstant('{app}\mysql\import-data-into-mysql-v2.bat'), False, True, False);
|
||||
|
||||
|
||||
// 删除默认 Readme.md
|
||||
if FileExists(ExpandConstant('{app}\io\Readme.md')) then
|
||||
DeleteFile(ExpandConstant('{app}\io\Readme.md'));
|
||||
|
||||
if FileExists(ExpandConstant('{app}\jdk\Readme.md')) then
|
||||
DeleteFile(ExpandConstant('{app}\jdk\Readme.md'));
|
||||
|
||||
if FileExists(ExpandConstant('{app}\mysql\Readme.md')) then
|
||||
DeleteFile(ExpandConstant('{app}\mysql\Readme.md'));
|
||||
|
||||
if FileExists(ExpandConstant('{app}\nginx\Readme.md')) then
|
||||
DeleteFile(ExpandConstant('{app}\nginx\Readme.md'));
|
||||
|
||||
end;
|
||||
|
||||
|
||||
|
||||
// 初始化并启动MySQL
|
||||
procedure InitializeAndStartMySQL;
|
||||
var
|
||||
ResultCode: Integer;
|
||||
Cmd: string;
|
||||
begin
|
||||
|
||||
// 通过 mysql 初始化生成的唯一 uuid 判断 mysql 是否已经完成初始化
|
||||
if not FileExists(ExpandConstant('{app}\mysql\data\auto.cnf')) then
|
||||
begin
|
||||
// 如果没有完成初始化,则判断是否存在 readme.md 文件 即完全没有初始化
|
||||
if FileExists(ExpandConstant('{app}\mysql\data\Readme.md')) then
|
||||
begin
|
||||
// 如果没有初始化,则删除 readme
|
||||
DelTree(ExpandConstant('{app}\mysql\data\Readme.md'), False, True, False);
|
||||
DelayMS(200);
|
||||
end;
|
||||
|
||||
|
||||
// 存在默认库SQL压缩包
|
||||
if FileExists(ExpandConstant('{app}\mysql\database.rar')) then
|
||||
begin
|
||||
// 解压
|
||||
if not Exec('cmd.exe', '/C " cd ' + ExpandConstant('{app}') + '\mysql && %cd%\..\usr\unrar.exe x database.rar script\demo\"', '', SW_HIDE, ewNoWait, ResultCode) then
|
||||
begin
|
||||
MsgBox('解压 MySQL 默认库失败', mbError, MB_OK);
|
||||
end;
|
||||
|
||||
// 删除 database.rar 默认库SQL压缩包
|
||||
DelayMS(1000);
|
||||
DelTree(ExpandConstant('{app}\mysql\database.rar'), False, True, False);
|
||||
end;
|
||||
DelayMS(1000);
|
||||
|
||||
|
||||
// 初始化
|
||||
// 同步 ewWaitUntilTerminated
|
||||
// 异步 ewNoWait
|
||||
|
||||
// 初始化并启动 MySQL
|
||||
// Cmd := '/C "' + ExpandConstant('{app}') + '\mysql\initialize-and-start-mysql.bat"';
|
||||
Cmd := '/C " cd ' + ExpandConstant('{app}') + '\mysql && initialize.bat"';
|
||||
if not Exec('cmd.exe', Cmd, '', SW_HIDE, ewNoWait, ResultCode) then
|
||||
begin
|
||||
MsgBox('初始化 MySQL 脚本失败', mbError, MB_OK);
|
||||
end else begin
|
||||
DelayMS(3000);
|
||||
// DeleteFile(ExpandConstant('{app}\mysql\initialize-and-start-mysql.bat'));
|
||||
DeleteFile(ExpandConstant('{app}\mysql\register-mysql-with-data.bat'));
|
||||
// DeleteFile(ExpandConstant('{app}\mysql\initialize.bat'));
|
||||
end;
|
||||
DelayMS(1000);
|
||||
|
||||
|
||||
end; // mysql auto.conf 初始化判定
|
||||
end;
|
||||
|
||||
|
||||
|
||||
// 导入默认数据库到 MySQL
|
||||
// procedure ImportDefaultDatabase2MySQL;
|
||||
// var
|
||||
// ResultCode: Integer;
|
||||
// Cmd: string;
|
||||
// MySQLPath: string;
|
||||
// UsrPath: string;
|
||||
// begin
|
||||
//
|
||||
// // 判断是否安装了 usr 基础环境
|
||||
// if FileExists(ExpandConstant('{app}\usr\rar.exe')) then
|
||||
// begin
|
||||
//
|
||||
// // 等待 MySQL 服务启动完成
|
||||
// DelayMS(3000);
|
||||
// // 这个时候 `环境变量` 还没开始注册,所以 bat 导入脚本不生效,因此需要指定临时Path环境变量
|
||||
// // 导出默认库和用户
|
||||
// if FileExists(ExpandConstant('{app}\mysql\import-data-into-mysql.bat')) then
|
||||
// begin
|
||||
//
|
||||
// // 临时设置 PATH 并执行脚本
|
||||
// MySQLPath := ExpandConstant('{app}') + '\mysql\bin';
|
||||
// UsrPath := ExpandConstant('{app}') + '\usr';
|
||||
// Cmd := '/C "set PATH=' + MySQLPath + '; ' + UsrPath + ';%PATH%' +
|
||||
// ' && cd ' + ExpandConstant('{app}') + '\mysql' +
|
||||
// ' && import-data-into-mysql.bat"' +
|
||||
// ' && exit"';
|
||||
//
|
||||
// if not Exec('cmd.exe', Cmd, '', SW_HIDE, ewNoWait, ResultCode) then
|
||||
// begin
|
||||
// MsgBox('初始化默认库脚本失败', mbError, MB_OK);
|
||||
// end;
|
||||
// DelayMS(1000);
|
||||
// end;
|
||||
// end; // 是否安装了 usr 环境
|
||||
//
|
||||
// end;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -427,6 +650,7 @@ function InitializeSetup: Boolean;
|
||||
begin
|
||||
// 默认允许安装继续
|
||||
Result := True;
|
||||
|
||||
// 如果 VC++ 2019 未安装
|
||||
if not IsVC2019Installed then
|
||||
begin
|
||||
@ -434,40 +658,46 @@ begin
|
||||
// 中止安装
|
||||
Result := False;
|
||||
end;
|
||||
|
||||
end;
|
||||
|
||||
|
||||
// 在安装完成后执行
|
||||
procedure CurStepChanged(CurStep: TSetupStep);
|
||||
begin
|
||||
|
||||
// 仅在安装完成后执行
|
||||
if CurStep = ssPostInstall then
|
||||
begin
|
||||
// 创建配置文件
|
||||
CreateConfigFromTemplate;
|
||||
// 创建配置文件
|
||||
CreateConfigFromTemplate;
|
||||
|
||||
// 删除模版文件
|
||||
if FileExists(ExpandConstant('{app}\mysql\template.ini')) then
|
||||
DeleteFile(ExpandConstant('{app}\mysql\template.ini'));
|
||||
// 删除过程文件
|
||||
RemoveTempFile;
|
||||
|
||||
if FileExists(ExpandConstant('{app}\mysql\template-initialize-and-start-mysql.bat')) then
|
||||
DelTree(ExpandConstant('{app}\mysql\template-initialize-and-start-mysql.bat'), False, True, False);
|
||||
// 初始化并启动 MySQL
|
||||
InitializeAndStartMySQL;
|
||||
|
||||
// 导入默认数据库到 MySQL
|
||||
// ImportDefaultDatabase2MySQL;
|
||||
end; // 安装完成后的执行
|
||||
|
||||
if FileExists(ExpandConstant('{app}\mysql\template-register-mysql-with-data.bat')) then
|
||||
DelTree(ExpandConstant('{app}\mysql\template-register-mysql-with-data.bat'), False, True, False);
|
||||
|
||||
if FileExists(ExpandConstant('{app}\mysql\import-data-into-mysql-v2.bat')) then
|
||||
DelTree(ExpandConstant('{app}\mysql\import-data-into-mysql-v2.bat'), False, True, False);
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
// 卸载前先停止程序运行
|
||||
procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
|
||||
var
|
||||
hSCManager, hService: Longword;
|
||||
ServiceStatus: Longword;
|
||||
ResultCode: Integer;
|
||||
DataDir: string;
|
||||
begin
|
||||
if CurUninstallStep = usUninstall then begin
|
||||
// 在这里执行你的脚本或程序
|
||||
// Exec(ExpandConstant('{cmd}'), '/C "uninstall_script.bat"', '', SW_HIDE, ewWaitUntilTerminated, ResultCode);
|
||||
|
||||
end;
|
||||
end;
|
||||
|
||||
@ -478,11 +708,22 @@ Filename: "sc"; Parameters: "stop redis"; Flags: runascurrentuser runhidden wait
|
||||
Filename: "sc"; Parameters: "delete redis"; Flags: runascurrentuser runhidden waituntilterminated
|
||||
Filename: "sc"; Parameters: "stop x_database"; Flags: runascurrentuser runhidden waituntilterminated
|
||||
Filename: "sc"; Parameters: "delete x_database"; Flags: runascurrentuser runhidden waituntilterminated
|
||||
Filename: "taskkill"; Parameters: "-f -im home-web.exe"; Flags: runascurrentuser runhidden waituntilterminated
|
||||
|
||||
|
||||
;; 卸载时删除的文件
|
||||
[UninstallDelete]
|
||||
; 删除 mysql 相关内容(停止服务可能需要一定时间,因此删除mysql时可能存在占用问题导致删除失败,需要转到 code 实现)
|
||||
Type: files; Name: "{app}\mysql\my.ini"
|
||||
Type: files; Name: "{app}\mysql\*.bat"
|
||||
Type: filesandordirs; Name: "{app}\mysql\data"
|
||||
Type: filesandordirs; Name: "{app}\mysql\lib"
|
||||
Type: filesandordirs; Name: "{app}\mysql\bin"
|
||||
; 删除 minio 数据
|
||||
Type: filesandordirs; Name: "{app}\io"
|
||||
Type: filesandordirs; Name: "{app}\io\data"
|
||||
; 删除 nginx log
|
||||
Type: filesandordirs; Name: "{app}\nginx\logs"
|
||||
; 删除 rocketmq 数据
|
||||
Type: filesandordirs; Name: "{app}\rocketmq\sbin\store"
|
||||
|
||||
|
@ -4,6 +4,9 @@
|
||||
# 版本: v0.0.2
|
||||
# 功能: 转化工具,将 ps1 转为可执行 exe 文件
|
||||
|
||||
# Get-Module -ListAvailable -Name PS2EXE
|
||||
# Install-Module ps2exe
|
||||
#
|
||||
# Set-ExecutionPolicy RemoteSigned -Scope Process -Force
|
||||
# Import-Module ps2exe -ErrorAction Stop
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
#!PowerShell
|
||||
#!PowerShell
|
||||
|
||||
######################################################################
|
||||
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,8 +1,10 @@
|
||||
;iss
|
||||
|
||||
; 构建时间:1.0.22 => 2025-8-18 19:47:00
|
||||
; 构建时间:1.0.23 => 2025-9-19 19:23:21
|
||||
; 构建时间:1.0.24 => 2025-9-20 11:14:40
|
||||
; 构建时间:1.0.25 => 2025-9-20 12:42:38
|
||||
#define MyAppName "模型管理"
|
||||
#define MyAppVersion "1.0.22"
|
||||
#define MyAppVersion "1.0.25"
|
||||
#define MyAppVersionString "v" + MyAppVersion
|
||||
#define MyAppPublisher "X"
|
||||
#define MyAppURL "~"
|
||||
@ -215,6 +217,7 @@ Root: HKLM; Subkey: "SYSTEM\CurrentControlSet\Control\Session Manager\Environmen
|
||||
Root: HKLM; Subkey: "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"; ValueType: string; Flags: uninsdeletevalue; Components: Server; \
|
||||
ValueName: "{#MyAppExeNameUpper}_VM_PARAMS"; ValueData: " \
|
||||
--enable-preview \
|
||||
-Dspring.profiles.active=dev,mysql \
|
||||
-Dserver.port=28680 \
|
||||
-Dproject.database-name=model \
|
||||
-Dproject.minio-url=http://127.0.0.1:9000 \
|
||||
|
@ -1,8 +1,12 @@
|
||||
;iss
|
||||
|
||||
; 构建时间:2025-8-18 14:13:19
|
||||
; shzyh!234
|
||||
|
||||
; 构建版本:1.0.27
|
||||
; 构建时间:2025-9-24 21:11:48
|
||||
#define MyAppName "模型管理"
|
||||
#define MyAppVersion "1.0.19"
|
||||
#define MyAppVersion "1.0.27"
|
||||
#define MyAppVersionString "v" + MyAppVersion
|
||||
#define MyAppPublisher "X"
|
||||
#define MyAppURL "~"
|
||||
#define MyAppExeName "model"
|
||||
@ -52,7 +56,7 @@ PrivilegesRequired=admin
|
||||
ArchitecturesAllowed=x64compatible
|
||||
ArchitecturesInstallIn64BitMode=x64compatible
|
||||
OutputDir=Release\
|
||||
OutputBaseFilename={#MyAppExeNameHump}Setup-{#MyAppVersion}-783
|
||||
OutputBaseFilename={#MyAppExeNameHump}Setup-{#MyAppVersionString}-783
|
||||
UninstallFilesDir={app}\{#MyAppExeName}
|
||||
UninstallDisplayIcon={app}\{#MyAppExeName}\{#MyAppExeName}.exe
|
||||
|
||||
@ -119,6 +123,7 @@ Source: "{#MyAppResources}\patch.exe"; DestDir: "{app}\{#MyAppExeName}"; DestNam
|
||||
;Windows 10 环境,不提供 bat 启动
|
||||
;Source: "{#MyAppResources}\{#MyAppExeName}.bat"; DestDir: "{app}\{#MyAppExeName}"; DestName: "{#MyAppExeName}.bat"; Flags: ignoreversion; Components: Starter;
|
||||
Source: "{#MyAppResources}\server\demo-0.0.1.jar"; DestDir: "{app}\{#MyAppExeName}\bin"; Flags: ignoreversion; Components: Server;
|
||||
Source: "{#MyAppResources}\lib\*"; DestDir: "{app}\{#MyAppExeName}\lib"; Flags: ignoreversion recursesubdirs createallsubdirs; Components: Server
|
||||
|
||||
; 更新数据库脚本
|
||||
Source: "{#MyAppResources}\script\*"; DestDir: "{app}\{#MyAppExeName}\script"; Flags: ignoreversion recursesubdirs createallsubdirs; Components: Server;
|
||||
@ -212,9 +217,12 @@ Root: HKLM; Subkey: "SYSTEM\CurrentControlSet\Control\Session Manager\Environmen
|
||||
ValueName: "{#MyAppExeNameUpper}_MANAGE_DB_PORT"; ValueData: "33306";
|
||||
Root: HKLM; Subkey: "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"; ValueType: string; Flags: uninsdeletevalue; Components: Server; \
|
||||
ValueName: "{#MyAppExeNameUpper}_VM_PARAMS"; ValueData: " \
|
||||
-Dloader.path=""{app}\{#MyAppExeName}\lib"" \
|
||||
--enable-preview \
|
||||
-Dspring.profiles.active=dev,mysql \
|
||||
-Dserver.port=28680 \
|
||||
-Dproject.database-name=model \
|
||||
-Dproject.minio-url=http://127.0.0.1:9000 \
|
||||
";
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user