【783】executor
This commit is contained in:
parent
b79940f524
commit
402c52b00a
31
server/model_full/Execute/win10_783/convert.bat
Normal file
31
server/model_full/Execute/win10_783/convert.bat
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
@echo off
|
||||||
|
setlocal
|
||||||
|
|
||||||
|
:: 时间: 2023-10-14 17:54:07
|
||||||
|
:: 作者: 岳佳君
|
||||||
|
:: 版本: v0.0.2
|
||||||
|
:: 功能: 调用同名 ps1 脚本,临时授权可执行
|
||||||
|
|
||||||
|
:: 获取当前批处理脚本的目录和名称
|
||||||
|
set "bat_path=%~dp0"
|
||||||
|
set "script_name=%~n0"
|
||||||
|
|
||||||
|
:: 检查同目录下的同名 .ps1 文件是否存在
|
||||||
|
if not exist "%bat_path%%script_name%.ps1" (
|
||||||
|
echo Error: PowerShell script "%bat_path%%script_name%.ps1" not found!
|
||||||
|
pause
|
||||||
|
exit /b 1
|
||||||
|
)
|
||||||
|
|
||||||
|
:: 以 UTF-8 编码运行 PowerShell 脚本
|
||||||
|
echo Running PowerShell script (UTF-8): "%bat_path%%script_name%.ps1"
|
||||||
|
powershell.exe -ExecutionPolicy Bypass -Command "& { [Console]::OutputEncoding = [System.Text.Encoding]::UTF8; . \"%bat_path%%script_name%.ps1\"; exit $LASTEXITCODE }"
|
||||||
|
|
||||||
|
:: 检查执行是否成功
|
||||||
|
if errorlevel 1 (
|
||||||
|
echo Error: Failed to execute PowerShell script.
|
||||||
|
pause
|
||||||
|
exit /b %errorlevel%
|
||||||
|
)
|
||||||
|
|
||||||
|
endlocal
|
28
server/model_full/Execute/win10_783/convert.ps1
Normal file
28
server/model_full/Execute/win10_783/convert.ps1
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
#!PowerShell
|
||||||
|
|
||||||
|
# 时间: 2025-8-6 15:24:00
|
||||||
|
# 版本: v0.0.2
|
||||||
|
# 功能: 转化工具,将 ps1 转为可执行 exe 文件
|
||||||
|
|
||||||
|
# Set-ExecutionPolicy RemoteSigned -Scope Process -Force
|
||||||
|
# Import-Module ps2exe -ErrorAction Stop
|
||||||
|
|
||||||
|
Set-ExecutionPolicy RemoteSigned -Scope Process -Force
|
||||||
|
Write-Output "Convert EXE"
|
||||||
|
Import-Module ps2exe -ErrorAction Stop
|
||||||
|
|
||||||
|
# 转化参数
|
||||||
|
$PS1_NAME = "startup"
|
||||||
|
$APPLICATION_NAME = "model"
|
||||||
|
$APPLICATION_VERSION = "1.0.0"
|
||||||
|
$COPY_RIGHT = "© 2025"
|
||||||
|
|
||||||
|
# 基本启动,无 console,可配置开机自启
|
||||||
|
Invoke-PS2EXE -InputFile "${PS1_NAME}.ps1" -OutputFile "${APPLICATION_NAME}.exe" -IconFile "icon.ico" -version "${APPLICATION_VERSION}" -copyright "${COPY_RIGHT}" -requireAdmin -ErrorAction Stop
|
||||||
|
# 基本启动,提供 console,用于 debug
|
||||||
|
Invoke-PS2EXE -InputFile "${PS1_NAME}-console.ps1" -OutputFile "${APPLICATION_NAME}-console.exe" -IconFile "icon.ico" -version "${APPLICATION_VERSION}" -copyright "${COPY_RIGHT}" -requireAdmin -ErrorAction Stop
|
||||||
|
# 基本启动,两种x
|
||||||
|
Invoke-PS2EXE -InputFile "${PS1_NAME}.ps1" -OutputFile "${APPLICATION_NAME}-x86.exe" -IconFile "icon.ico" -version "${APPLICATION_VERSION}" -copyright "${COPY_RIGHT}" -x86 -requireAdmin -ErrorAction Stop
|
||||||
|
Invoke-PS2EXE -InputFile "${PS1_NAME}.ps1" -OutputFile "${APPLICATION_NAME}-x64.exe" -IconFile "icon.ico" -version "${APPLICATION_VERSION}" -copyright "${COPY_RIGHT}" -x64 -requireAdmin -ErrorAction Stop
|
||||||
|
Write-Host "Complete." -ForegroundColor Green
|
||||||
|
Start-Sleep -Seconds 1
|
BIN
server/model_full/Execute/win10_783/icon.ico
Normal file
BIN
server/model_full/Execute/win10_783/icon.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 85 KiB |
109
server/model_full/Execute/win10_783/patch.ps1
Normal file
109
server/model_full/Execute/win10_783/patch.ps1
Normal file
@ -0,0 +1,109 @@
|
|||||||
|
#!PowerShell
|
||||||
|
|
||||||
|
# Function: Import data from script files or RAR script files into MySQL specific libraries
|
||||||
|
# Author: JiangJun
|
||||||
|
# Create-Time: 2025-8-10 15:57:26
|
||||||
|
# Version: 0.3
|
||||||
|
|
||||||
|
# Set-ExecutionPolicy RemoteSigned -Scope Process -Force
|
||||||
|
|
||||||
|
$logFile = "ScriptExecutionLog_$(Get-Date -Format 'yyyyMMdd_HHmmss').txt"
|
||||||
|
|
||||||
|
function Write-Log {
|
||||||
|
param (
|
||||||
|
[string]$message
|
||||||
|
)
|
||||||
|
$timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
|
||||||
|
$logMessage = "[$timestamp] $message"
|
||||||
|
# [debug]
|
||||||
|
# Write-Output $logMessage | Out-File -FilePath $logFile -Append
|
||||||
|
Write-Host $logMessage
|
||||||
|
}
|
||||||
|
|
||||||
|
function randomText {
|
||||||
|
$chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'.ToCharArray()
|
||||||
|
$length = 12
|
||||||
|
$random = New-Object System.Random
|
||||||
|
$string = -join (1..$length | ForEach-Object { $chars[$random.Next(0, $chars.Length)] })
|
||||||
|
return $string
|
||||||
|
}
|
||||||
|
|
||||||
|
function Import-Script {
|
||||||
|
param (
|
||||||
|
[string]$dbServer,
|
||||||
|
[string]$dbPort,
|
||||||
|
[string]$dbUser,
|
||||||
|
[string]$dbPassword
|
||||||
|
)
|
||||||
|
if (Test-Path -Path ".\script" -PathType Container) {
|
||||||
|
Write-Log "Found script folder, starting to process .."
|
||||||
|
$subFolders = Get-ChildItem -Path ".\script" -Directory
|
||||||
|
if ($subFolders.Count -eq 0) {
|
||||||
|
Write-Log "There are no subfolders in the script folder, skipping processing."
|
||||||
|
exit
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($folder in $subFolders) {
|
||||||
|
Write-Log "Database connection parameters - Please modify according to the actual situation $($folder.Name)"
|
||||||
|
$rarFiles = Get-ChildItem -Path $folder.FullName -Filter "*.rar"
|
||||||
|
if ($rarFiles.Count -eq 0) {
|
||||||
|
Write-Log "There are no SQL files in the folder $($folder.Name), skipping."
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($rarFile in $rarFiles) {
|
||||||
|
Write-Log "Processing file: $($rarFile.Name) (located in $($folder.Name))"
|
||||||
|
$rarName = $rarFile.BaseName
|
||||||
|
$rarDirectoryName = (Get-Item $rarFile.FullName).DirectoryName
|
||||||
|
try {
|
||||||
|
Start-Process -FilePath "rar" -ArgumentList "x -pshzyh!234 `"$($rarFile.FullName)`" `"$rarDirectoryName`"" -NoNewWindow -Wait
|
||||||
|
if (Test-Path $rarFile.FullName) {
|
||||||
|
Remove-Item $rarFile.FullName -Force
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
Write-Log "Error unrar $($rarFile.Name):$_"
|
||||||
|
Write-Log "=> $($rarFile.FullName)"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($folder in $subFolders) {
|
||||||
|
Write-Log "Database connection parameters - Please modify according to the actual situation $($folder.Name)"
|
||||||
|
$sqlFiles = Get-ChildItem -Path $folder.FullName -Filter "*.sql"
|
||||||
|
if ($sqlFiles.Count -eq 0) {
|
||||||
|
Write-Log "There are no SQL files in the folder $($folder.Name), skipping."
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
foreach ($sqlFile in $sqlFiles) {
|
||||||
|
Write-Log "Processing file: $($sqlFile.Name) (located in $($folder.Name))"
|
||||||
|
$dbName = $sqlFile.BaseName
|
||||||
|
try {
|
||||||
|
Write-Log "Creating database $dbName and importing $($sqlFile.Name)"
|
||||||
|
Start-Process -FilePath "mysql" -ArgumentList "-h$dbServer -u$dbUser -p$dbPassword -P$dbPort $($folder.Name)" -RedirectStandardInput $sqlFile.FullName -NoNewWindow -Wait
|
||||||
|
Write-Log "Successfully imported $($sqlFile.Name) into database $($folder.Name)"
|
||||||
|
|
||||||
|
$date = $(Get-Date -Format "yyyy-MM-dd")
|
||||||
|
$random = randomText
|
||||||
|
$target = ".\patch\$($date)"
|
||||||
|
New-Item -Path "$target" -ItemType Directory -Force
|
||||||
|
Start-Process -FilePath "rar" -ArgumentList "a -pPassword#$date! -hp $target\$($random).rar `"$($sqlFile.FullName)`"" -NoNewWindow -Wait
|
||||||
|
|
||||||
|
if (Test-Path $sqlFile.FullName) {
|
||||||
|
Remove-Item $sqlFile.FullName -Force
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
Write-Log "Error importing $($sqlFile.Name):$_"
|
||||||
|
Write-Log "=> $($sqlFile.FullName)"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Log "All script processing has been completed."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Param 1: MySQL IP
|
||||||
|
# Param 2: MySQL Port
|
||||||
|
# Param 3: MySQL root
|
||||||
|
# Param 4: MySQL root_password
|
||||||
|
Import-Script "127.0.0.1" "33306" "root" "Root@2025"
|
53
server/model_full/Execute/win10_783/shutdown.bat
Normal file
53
server/model_full/Execute/win10_783/shutdown.bat
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
@ECHO OFF
|
||||||
|
|
||||||
|
:: 时间: 2025-8-3 14:18:20
|
||||||
|
:: 作者: JiangJun
|
||||||
|
:: 版本: 0.0.4
|
||||||
|
:: 功能: 关闭 springboot 整体服务(需要配合 XManage 运行环境)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
:: Nginx 执行 EXE 名称
|
||||||
|
set "nginx_name=model-web.exe"
|
||||||
|
|
||||||
|
:: Nginx 代理端口号
|
||||||
|
set "nginx_proxy_port=:18680"
|
||||||
|
|
||||||
|
:: 服务端口号
|
||||||
|
set "server_port=:28680"
|
||||||
|
|
||||||
|
:: 数据库端口号
|
||||||
|
set "database_port=:33306"
|
||||||
|
|
||||||
|
:: MinIO端口号
|
||||||
|
set "minio_port=:9000"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
:: 关闭web
|
||||||
|
set "X="
|
||||||
|
for /f %%a in ('netstat -ano ^| grep -v "WAIT" ^| grep "%nginx_proxy_port%" ^| head -n 1 ^| awk "{print $NF}"') do @(set X=%%a)
|
||||||
|
if defined X taskkill -f -pid %X%
|
||||||
|
|
||||||
|
:: 关闭代理
|
||||||
|
set "X="
|
||||||
|
for /f %%a in ('tasklist ^| grep -v "WAIT" ^| grep "%nginx_name%" ^| head -n 1 ^| awk "{print $1}"') do @(set X=%%a)
|
||||||
|
if defined X taskkill -f -im "%nginx_name%"
|
||||||
|
|
||||||
|
:: 关闭后端
|
||||||
|
set "X="
|
||||||
|
for /f %%a in ('netstat -ano ^| grep -v "WAIT" ^| grep "%server_port%" ^| head -n 1 ^| awk "{print $NF}"') do @(set X=%%a)
|
||||||
|
if defined X taskkill -f -pid %X%
|
||||||
|
|
||||||
|
:: 停止数据库服务
|
||||||
|
set "X="
|
||||||
|
for /f %%a in ('netstat -ano ^| grep -v "WAIT" ^| grep "%database_port%" ^| head -n 1 ^| awk "{print $NF}"') do @(set X=%%a)
|
||||||
|
if defined X net stop x_database
|
||||||
|
|
||||||
|
:: 关闭MinIO
|
||||||
|
set "X="
|
||||||
|
for /f %%a in ('netstat -ano ^| grep -v "WAIT" ^| grep "%minio_port%" ^| head -n 1 ^| awk "{print $NF}"') do @(set X=%%a)
|
||||||
|
if defined X taskkill -f -pid %X%
|
||||||
|
|
||||||
|
:: pause
|
||||||
|
timeout /t 3 /nobreak >nul
|
530
server/model_full/Execute/win10_783/startup-console.ps1
Normal file
530
server/model_full/Execute/win10_783/startup-console.ps1
Normal file
@ -0,0 +1,530 @@
|
|||||||
|
#!PowerShell
|
||||||
|
|
||||||
|
######################################################################
|
||||||
|
|
||||||
|
# Function
|
||||||
|
# CreateTime: 2025-08-06 12:52:28
|
||||||
|
# Author: Yue Jiajun
|
||||||
|
# Version: 0.0.68
|
||||||
|
|
||||||
|
# Write-Host 是否输出
|
||||||
|
# false: 打包成 exe 时,需要设置为 false
|
||||||
|
# true: 直接运行 ps1时,可以为 true
|
||||||
|
$outputWriteHost = $true
|
||||||
|
$outputLogFile = "$MAIN_PATH\startup.log"
|
||||||
|
$outputErrorFile = "$MAIN_PATH\error.log"
|
||||||
|
######################################################################
|
||||||
|
|
||||||
|
# Get current path
|
||||||
|
$MAIN_PATH = Get-Location
|
||||||
|
|
||||||
|
# Get database service name
|
||||||
|
$SERVER_NAME = $env:X_MANAGE_DB_SC
|
||||||
|
|
||||||
|
# Nginx executable name
|
||||||
|
$NGINX_EXE = "model-web.exe"
|
||||||
|
|
||||||
|
|
||||||
|
# Log recording function
|
||||||
|
function Write-Log {
|
||||||
|
param (
|
||||||
|
[string]$message
|
||||||
|
)
|
||||||
|
$timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
|
||||||
|
$logMessage = "[$timestamp] $message"
|
||||||
|
# [debug]
|
||||||
|
# Write-Output $logMessage | Out-File -FilePath $logFile -Append
|
||||||
|
Write-Host $logMessage
|
||||||
|
}
|
||||||
|
|
||||||
|
function randomText {
|
||||||
|
$chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'.ToCharArray()
|
||||||
|
$length = 12
|
||||||
|
$random = New-Object System.Random
|
||||||
|
$string = -join (1..$length | ForEach-Object { $chars[$random.Next(0, $chars.Length)] })
|
||||||
|
return $string
|
||||||
|
}
|
||||||
|
|
||||||
|
function Import-Script {
|
||||||
|
param (
|
||||||
|
[string]$dbServer,
|
||||||
|
[string]$dbPort,
|
||||||
|
[string]$dbUser,
|
||||||
|
[string]$dbPassword
|
||||||
|
)
|
||||||
|
# Check whether the script folder exists in the current path
|
||||||
|
if (Test-Path -Path ".\script" -PathType Container) {
|
||||||
|
Write-Log "Found script folder, starting to process .."
|
||||||
|
|
||||||
|
# Get all subfolders
|
||||||
|
$subFolders = Get-ChildItem -Path ".\script" -Directory
|
||||||
|
|
||||||
|
if ($subFolders.Count -eq 0) {
|
||||||
|
Write-Log "There are no subfolders in the script folder, skipping processing."
|
||||||
|
exit
|
||||||
|
}
|
||||||
|
|
||||||
|
# Traverse each subfolder
|
||||||
|
foreach ($folder in $subFolders) {
|
||||||
|
Write-Log "Database connection parameters - Please modify according to the actual situation $($folder.Name)"
|
||||||
|
|
||||||
|
# Get all RAR files under this folder
|
||||||
|
$rarFiles = Get-ChildItem -Path $folder.FullName -Filter "*.rar"
|
||||||
|
|
||||||
|
if ($rarFiles.Count -eq 0) {
|
||||||
|
Write-Log "There are no SQL files in the folder $($folder.Name), skipping."
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
# Process each SQL file
|
||||||
|
foreach ($rarFile in $rarFiles) {
|
||||||
|
Write-Log "Processing file: $($rarFile.Name) (located in $($folder.Name))"
|
||||||
|
|
||||||
|
$rarName = $rarFile.BaseName
|
||||||
|
$rarDirectoryName = (Get-Item $rarFile.FullName).DirectoryName
|
||||||
|
try {
|
||||||
|
Start-Process -FilePath "rar" -ArgumentList "x -pshzyh!234 `"$($rarFile.FullName)`" `"$rarDirectoryName`"" -NoNewWindow -Wait
|
||||||
|
|
||||||
|
# Remove rar-file
|
||||||
|
if (Test-Path $rarFile.FullName) {
|
||||||
|
Remove-Item $rarFile.FullName -Force
|
||||||
|
# [debug]
|
||||||
|
# Write-Log "File deleted."
|
||||||
|
} else {
|
||||||
|
# [debug]
|
||||||
|
# Write-Log "File does not exist."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
Write-Log "Error unrar $($rarFile.Name):$_"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Traverse each subfolder
|
||||||
|
foreach ($folder in $subFolders) {
|
||||||
|
Write-Log "Database connection parameters - Please modify according to the actual situation $($folder.Name)"
|
||||||
|
|
||||||
|
# Get all SQL files under this folder
|
||||||
|
$sqlFiles = Get-ChildItem -Path $folder.FullName -Filter "*.sql"
|
||||||
|
|
||||||
|
if ($sqlFiles.Count -eq 0) {
|
||||||
|
Write-Log "There are no SQL files in the folder $($folder.Name), skipping."
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
# Process each SQL file
|
||||||
|
foreach ($sqlFile in $sqlFiles) {
|
||||||
|
Write-Log "Processing file: $($sqlFile.Name) (located in $($folder.Name))"
|
||||||
|
|
||||||
|
# Use file name as database name (without extension)
|
||||||
|
$dbName = $sqlFile.BaseName
|
||||||
|
try {
|
||||||
|
# Connect to the database and execute SQL files
|
||||||
|
Write-Log "Creating database $dbName and importing $($sqlFile.Name)"
|
||||||
|
|
||||||
|
# Here we use MySQL client as an example. If it is SQL Server, please modify it to the corresponding command
|
||||||
|
# For SQL Server, you can use sqlcmd or Invoke sqlcmd
|
||||||
|
# $command = "mysql -h$dbServer -u$dbUser -p$dbPassword -P$dbPort -e 'CREATE DATABASE IF NOT EXISTS $dbName;'"
|
||||||
|
# Invoke-Expression $command
|
||||||
|
|
||||||
|
# $command = "mysql -h$dbServer -u$dbUser -p$dbPassword -P$dbPort $dbName `< `"$($sqlFile.FullName)`""
|
||||||
|
$command = "mysql -h$dbServer -u$dbUser -p$dbPassword -P$dbPort $($folder.Name) `< `"$($sqlFile.FullName)`""
|
||||||
|
|
||||||
|
# [debug]
|
||||||
|
# Write-Log $command
|
||||||
|
|
||||||
|
# Invoke-Expression $command # ERROR
|
||||||
|
# cmd /c $command # SUCCESS, WARN: >> CategoryInfo: NotSpecified: (mysql: [Warning...an be insecure.:String) [], RemoteException
|
||||||
|
# Get-Content $sqlFile.FullName | Invoke-Expression $command # ERROR
|
||||||
|
Start-Process -FilePath "mysql" -ArgumentList "-h$dbServer -u$dbUser -p$dbPassword -P$dbPort $($folder.Name)" -RedirectStandardInput $sqlFile.FullName -NoNewWindow -Wait
|
||||||
|
|
||||||
|
# Write-Log "Successfully imported $($sqlFile.Name) into database $dbName"
|
||||||
|
Write-Log "Successfully imported $($sqlFile.Name) into database $($folder.Name)"
|
||||||
|
|
||||||
|
$date = $(Get-Date -Format "yyyy-MM-dd")
|
||||||
|
$random = randomText
|
||||||
|
$target = ".\patch\$($date)"
|
||||||
|
New-Item -Path "$target" -ItemType Directory -Force
|
||||||
|
# cmd /c rar a -pPassword -hp "target.rar" "file"
|
||||||
|
# Start-Process -FilePath "rar" -ArgumentList "a -pPassword -hp "target.rar" "file"" -NoNewWindow -Wait
|
||||||
|
# Start-Process -FilePath "rar" -ArgumentList 'a', '-pPassword', '-hpPassword', 'target.rar', 'file' -NoNewWindow -Wait
|
||||||
|
Start-Process -FilePath "rar" -ArgumentList "a -pPassword#20250810! -hp $target\$($random).rar `"$($sqlFile.FullName)`"" -NoNewWindow -Wait
|
||||||
|
|
||||||
|
# Remove script-file
|
||||||
|
if (Test-Path $sqlFile.FullName) {
|
||||||
|
Remove-Item $sqlFile.FullName -Force
|
||||||
|
# [debug]
|
||||||
|
# Write-Log "File deleted."
|
||||||
|
} else {
|
||||||
|
# [debug]
|
||||||
|
# Write-Log "File does not exist."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
Write-Log "Error importing $($sqlFile.Name):$_"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Log "All script processing has been completed."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function Append-Utf8NoBomContent {
|
||||||
|
param (
|
||||||
|
[Parameter(Mandatory=$true)]
|
||||||
|
[string]$FilePath,
|
||||||
|
|
||||||
|
[Parameter(Mandatory=$true)]
|
||||||
|
[string]$Content
|
||||||
|
)
|
||||||
|
|
||||||
|
# 确保目录存在,如果不存在则创建
|
||||||
|
$directory = [System.IO.Path]::GetDirectoryName($FilePath)
|
||||||
|
if (-not [System.IO.Directory]::Exists($directory)) {
|
||||||
|
New-Item -ItemType Directory -Path $directory -Force | Out-Null
|
||||||
|
}
|
||||||
|
|
||||||
|
# 使用 UTF-8(无 BOM)追加内容
|
||||||
|
# 需要PowerShell 6+
|
||||||
|
# $Content | Out-File -FilePath $FilePath -Append -Encoding utf8NoBOM
|
||||||
|
|
||||||
|
# 检查文件是否存在,如果不存在则先创建一个空文件(避免 BOM 问题)
|
||||||
|
if (-not (Test-Path -Path $FilePath)) {
|
||||||
|
# 使用 .NET 创建空文件(无 BOM)
|
||||||
|
[System.IO.File]::WriteAllText($FilePath, "", [System.Text.Encoding]::UTF8)
|
||||||
|
}
|
||||||
|
|
||||||
|
# 使用 .NET 方法追加内容(UTF-8 无 BOM)
|
||||||
|
[System.IO.File]::AppendAllText($FilePath, "$Content`r`n", [System.Text.Encoding]::UTF8)
|
||||||
|
}
|
||||||
|
|
||||||
|
function Go-Home {
|
||||||
|
if($outputWriteHost) {
|
||||||
|
Write-Host ""
|
||||||
|
Write-Host "Exit ..."
|
||||||
|
}
|
||||||
|
$logMessage = "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') - 任务执行完成"
|
||||||
|
Append-Utf8NoBomContent -FilePath $outputLogFile -Content $logMessage
|
||||||
|
Start-Sleep -Seconds 5
|
||||||
|
exit 0
|
||||||
|
}
|
||||||
|
|
||||||
|
function Usage-MySQL {
|
||||||
|
if($outputWriteHost) {
|
||||||
|
Write-Host "ERROR: Please configure value in the system environment variable."
|
||||||
|
Write-Host "env: - X_MANAGE_DB_EXE"
|
||||||
|
Write-Host " - X_MANAGE_DB_COF"
|
||||||
|
Write-Host "skip database"
|
||||||
|
Write-Host ""
|
||||||
|
}
|
||||||
|
pause
|
||||||
|
Go-Home
|
||||||
|
}
|
||||||
|
|
||||||
|
function Usage-SpringBoot {
|
||||||
|
if($outputWriteHost) {
|
||||||
|
Write-Host "ERROR: Please configure `"JDK_21`" in the system environment variable."
|
||||||
|
}
|
||||||
|
pause
|
||||||
|
Go-Home
|
||||||
|
}
|
||||||
|
|
||||||
|
function Install-MySQL-Server {
|
||||||
|
# Check required environment variables
|
||||||
|
if (-not $env:X_MANAGE_DB_EXE) {
|
||||||
|
if($outputWriteHost) {
|
||||||
|
Write-Host "Error: Missing parameter! {X_MANAGE_DB_EXE}" | Out-File "error.log" -Append
|
||||||
|
}
|
||||||
|
Usage-MySQL
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (-not (Test-Path $env:X_MANAGE_DB_EXE)) {
|
||||||
|
if($outputWriteHost) {
|
||||||
|
Write-Host "Error: Missing parameter! {X_MANAGE_DB_EXE}" | Out-File "error.log" -Append
|
||||||
|
}
|
||||||
|
Usage-MySQL
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Host "exe: $($env:X_MANAGE_DB_EXE)"
|
||||||
|
$DB_EXEC = $env:X_MANAGE_DB_EXE
|
||||||
|
|
||||||
|
if (-not $env:X_MANAGE_DB_COF) {
|
||||||
|
if($outputWriteHost) {
|
||||||
|
Write-Host "Error: Missing parameter! {X_MANAGE_DB_COF}" | Out-File "error.log" -Append
|
||||||
|
}
|
||||||
|
Usage-MySQL
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (-not (Test-Path $env:X_MANAGE_DB_COF)) {
|
||||||
|
if($outputWriteHost) {
|
||||||
|
Write-Host "Error: Missing parameter! {X_MANAGE_DB_COF}" | Out-File "error.log" -Append
|
||||||
|
}
|
||||||
|
Usage-MySQL
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if($outputWriteHost) {
|
||||||
|
Write-Host "ini: $($env:X_MANAGE_DB_COF)"
|
||||||
|
}
|
||||||
|
$DB_CONF = $env:X_MANAGE_DB_COF
|
||||||
|
|
||||||
|
# Install MySQL service
|
||||||
|
& $DB_EXEC --install $SERVER_NAME --defaults-file="$DB_CONF"
|
||||||
|
|
||||||
|
# Configure service to start automatically
|
||||||
|
sc.exe config $SERVER_NAME start= auto
|
||||||
|
|
||||||
|
# Wait for service registration
|
||||||
|
Start-Sleep -Seconds 1
|
||||||
|
|
||||||
|
# Start the service
|
||||||
|
Start-Service -Name $SERVER_NAME
|
||||||
|
|
||||||
|
# Wait for service to start
|
||||||
|
Start-Sleep -Seconds 1
|
||||||
|
}
|
||||||
|
|
||||||
|
function Check-With-Start-MySQL {
|
||||||
|
# Check if service exists
|
||||||
|
$service = Get-Service -Name $SERVER_NAME -ErrorAction SilentlyContinue
|
||||||
|
|
||||||
|
if ($service) {
|
||||||
|
# Service exists, check if running
|
||||||
|
if ($service.Status -eq "Running") {
|
||||||
|
if($outputWriteHost) {
|
||||||
|
Write-Host "database ok."
|
||||||
|
}
|
||||||
|
$logMessage = "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') - 数据已运行..."
|
||||||
|
Append-Utf8NoBomContent -FilePath $outputLogFile -Content $logMessage
|
||||||
|
} else {
|
||||||
|
# Start the service if not running
|
||||||
|
if($outputWriteHost) {
|
||||||
|
Write-Host "start up ..."
|
||||||
|
}
|
||||||
|
$logMessage = "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') - 启动数据库中..."
|
||||||
|
Append-Utf8NoBomContent -FilePath $outputLogFile -Content $logMessage
|
||||||
|
Start-Service -Name $SERVER_NAME
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
# Install MySQL service
|
||||||
|
Install-MySQL-Server
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function Check-Web {
|
||||||
|
# 检查
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function Check-SpringBoot {
|
||||||
|
# 检查 JDK_21 环境变量
|
||||||
|
if (-not $env:JDK_21) {
|
||||||
|
# 如果不存在,则检查安装目录下是否存在 java 可执行文件
|
||||||
|
if (Test-Path "$MAIN_PATH\jre\bin\java.exe") {
|
||||||
|
$env:JDK_21 = "$MAIN_PATH\jre"
|
||||||
|
if($outputWriteHost) {
|
||||||
|
Write-Host "ONESELF"
|
||||||
|
}
|
||||||
|
$logMessage = "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') - JDK_21 环境变量不存在,默认生效: $env:JDK_21"
|
||||||
|
Append-Utf8NoBomContent -FilePath $outputLogFile -Content $logMessage
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (-not $env:JDK_21) {
|
||||||
|
Usage-SpringBoot
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
# 检查连接 DB 的 IP 地址
|
||||||
|
if (-not $env:MODEL_MANAGE_DB_SERVER) {
|
||||||
|
# 不存在,则默认 127
|
||||||
|
$env:MODEL_MANAGE_DB_SERVER = "127.0.0.1"
|
||||||
|
$logMessage = "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') - MODEL_MANAGE_DB_SERVER 环境变量不存在,默认生效: $env:MODEL_MANAGE_DB_SERVER"
|
||||||
|
Append-Utf8NoBomContent -FilePath $outputLogFile -Content $logMessage
|
||||||
|
}
|
||||||
|
|
||||||
|
# 检查连接 DB 的端口号
|
||||||
|
if (-not $env:MODEL_MANAGE_DB_PORT) {
|
||||||
|
# 不存在,则默认 3306
|
||||||
|
$env:MODEL_MANAGE_DB_PORT = "3306"
|
||||||
|
$logMessage = "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') - MODEL_MANAGE_DB_PORT 环境变量不存在,默认生效: $env:MODEL_MANAGE_DB_PORT"
|
||||||
|
Append-Utf8NoBomContent -FilePath $outputLogFile -Content $logMessage
|
||||||
|
}
|
||||||
|
|
||||||
|
# 检查 SpringBoot 启动 jar 文件环境变量
|
||||||
|
if (-not $env:MODEL_MANAGE_BIN) {
|
||||||
|
# 不存在,则默认安装目录下 bin
|
||||||
|
$env:MODEL_MANAGE_BIN = "$MAIN_PATH\bin\demo-0.0.1.jar"
|
||||||
|
$logMessage = "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') - MODEL_MANAGE_BIN 环境变量不存在,默认生效: $env:MODEL_MANAGE_BIN"
|
||||||
|
Append-Utf8NoBomContent -FilePath $outputLogFile -Content $logMessage
|
||||||
|
if (-not $env:MODEL_MANAGE_BIN) {
|
||||||
|
if($outputWriteHost) {
|
||||||
|
Write-Host "ERROR: Missing executable jar"
|
||||||
|
}
|
||||||
|
$logMessage = "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') - 缺少可执行的 jar"
|
||||||
|
Append-Utf8NoBomContent -FilePath $outputLogFile -Content $logMessage
|
||||||
|
pause
|
||||||
|
Go-Home
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if($outputWriteHost) {
|
||||||
|
Write-Host "jdk ok."
|
||||||
|
Write-Host ""
|
||||||
|
}
|
||||||
|
Start-Sleep -Seconds 1
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function Start-Web {
|
||||||
|
|
||||||
|
# 进入 web 下
|
||||||
|
Set-Location "$MAIN_PATH\web"
|
||||||
|
if($outputWriteHost) {
|
||||||
|
Write-Host "Start Web ..."
|
||||||
|
}
|
||||||
|
$logMessage = "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') - 准备Web启动..."
|
||||||
|
Append-Utf8NoBomContent -FilePath $outputLogFile -Content $logMessage
|
||||||
|
|
||||||
|
# Kill existing web service processes
|
||||||
|
Get-Process -Name $NGINX_EXE.Replace(".exe", "") -ErrorAction SilentlyContinue | Stop-Process -Force
|
||||||
|
|
||||||
|
# 配置默认启动参数
|
||||||
|
$NGINX_PATH = $NGINX_EXE
|
||||||
|
if (-not $NGINX_PATH) {
|
||||||
|
# 不存在,则默认安装目录下 nginx.exe
|
||||||
|
# $NGINX_PATH = "$MAIN_PATH\nginx.exe"
|
||||||
|
$NGINX_PATH = "nginx.exe"
|
||||||
|
if (-not $NGINX_PATH) {
|
||||||
|
if($outputWriteHost) {
|
||||||
|
Write-Host "ERROR: Missing executable web."
|
||||||
|
}
|
||||||
|
pause
|
||||||
|
Go-Home
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if($outputWriteHost) {
|
||||||
|
Write-Host "$NGINX_PATH"
|
||||||
|
}
|
||||||
|
$logMessage = "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') - Web生效可执行器: $NGINX_PATH"
|
||||||
|
Append-Utf8NoBomContent -FilePath $outputLogFile -Content $logMessage
|
||||||
|
|
||||||
|
# 检查 Nginx 配置文件是否存在,优先使用 web.conf
|
||||||
|
# $NGINX_CONFIG = "$MAIN_PATH\conf\web.conf"
|
||||||
|
$NGINX_CONFIG = "conf\web.conf"
|
||||||
|
if (-not $NGINX_CONFIG) {
|
||||||
|
# 不存在,则默认安装目录下 nginx.conf
|
||||||
|
# $NGINX_CONFIG = "$MAIN_PATH\conf\nginx.conf"
|
||||||
|
$NGINX_CONFIG = "conf\nginx.conf"
|
||||||
|
if (-not $NGINX_CONFIG) {
|
||||||
|
if($outputWriteHost) {
|
||||||
|
Write-Host "ERROR: Missing web config"
|
||||||
|
}
|
||||||
|
pause
|
||||||
|
Go-Home
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if($outputWriteHost) {
|
||||||
|
Write-Host "$NGINX_CONFIG"
|
||||||
|
}
|
||||||
|
$logMessage = "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') - Web配置生效文件: $NGINX_CONFIG"
|
||||||
|
Append-Utf8NoBomContent -FilePath $outputLogFile -Content $logMessage
|
||||||
|
|
||||||
|
# 创建以管理员身份运行的 VBS脚本(类似于原始的批处理方式)
|
||||||
|
$vbsContent = @"
|
||||||
|
Set UAC = CreateObject("Shell.Application")
|
||||||
|
Set WshShell = CreateObject("WScript.Shell")
|
||||||
|
|
||||||
|
On Error Resume Next
|
||||||
|
Set fso = CreateObject("Scripting.FileSystemObject")
|
||||||
|
Set tempFile = fso.OpenTextFile("%SystemRoot%\System32\config\systemprofile", 1)
|
||||||
|
If Err.Number = 0 Then
|
||||||
|
WshShell.Run "$NGINX_PATH -c $NGINX_CONFIG", 0, False
|
||||||
|
Else
|
||||||
|
UAC.ShellExecute "$NGINX_PATH", "-c $NGINX_CONFIG", "", "runas", 0
|
||||||
|
End If
|
||||||
|
"@
|
||||||
|
|
||||||
|
# 以 UTF-8 写入文件 temp.vbs ,vbs 脚本不能使用 utf-8
|
||||||
|
# $vbsContent | Out-File -FilePath "$MAIN_PATH\web\temp.vbs" -Encoding UTF8
|
||||||
|
# 以 ANSI 写入文件 temp.vbs
|
||||||
|
$vbsContent | Out-File -FilePath "$MAIN_PATH\web\temp.vbs" -Encoding ASCII
|
||||||
|
if($outputWriteHost) {
|
||||||
|
Write-Host "Build temporary startup script web."
|
||||||
|
}
|
||||||
|
|
||||||
|
# 运行 vbs 并等待结束
|
||||||
|
# Start-Process "cscript.exe" -ArgumentList "//nologo temp.vbs" -Wait
|
||||||
|
|
||||||
|
# 不等待,执行下一条命令,Nginx 本身是持续性窗口,等待会导致阻塞
|
||||||
|
Start-Process "cscript.exe" -ArgumentList "//nologo temp.vbs"
|
||||||
|
|
||||||
|
# 等待1秒后(防止上一条执行慢),删除临时文件
|
||||||
|
Start-Sleep -Seconds 1
|
||||||
|
Remove-Item "temp.vbs" -Force
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function Start-SpringBoot {
|
||||||
|
|
||||||
|
# 准备启动后台服务
|
||||||
|
Set-Location $MAIN_PATH
|
||||||
|
if($outputWriteHost) {
|
||||||
|
Write-Host "Start Server ..."
|
||||||
|
}
|
||||||
|
$logMessage = "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') - 准备SpringBoot启动..."
|
||||||
|
Append-Utf8NoBomContent -FilePath $outputLogFile -Content $logMessage
|
||||||
|
|
||||||
|
# jvm启动参数
|
||||||
|
# 指定环境变量 MODEL_MANAGE_DB_SERVER
|
||||||
|
# 指定环境变量 MODEL_MANAGE_DB_PORT
|
||||||
|
# 追加自定义JVM参数 MODEL_VM_PARAMS
|
||||||
|
$arguments = "-Dspring.profiles.active=dev,mysql -Dmybatis-flex.datasource.ds1.password=Wfbke8!LeMY5Fwwe -Dproject.database-ip=$env:MODEL_MANAGE_DB_SERVER -Dproject.database-port=$env:MODEL_MANAGE_DB_PORT $env:MODEL_VM_PARAMS"
|
||||||
|
$logMessage = "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') - 启动JVM参数: $arguments"
|
||||||
|
Append-Utf8NoBomContent -FilePath $outputLogFile -Content $logMessage
|
||||||
|
|
||||||
|
# 拆分参数为数组
|
||||||
|
$argumentList = $arguments -split " -"
|
||||||
|
|
||||||
|
# 处理第一个元素(没有前导"-")和其余元素(添加前导"-")
|
||||||
|
$argumentList = @($argumentList[0]) + ($argumentList[1..($argumentList.Length-1)] | ForEach-Object { "-$_" })
|
||||||
|
|
||||||
|
# 构建最终的调用命令
|
||||||
|
if($outputWriteHost) {
|
||||||
|
# Write-Host "$($env:JDK_21)\bin\java.exe" $argumentList -jar "$env:MODEL_MANAGE_BIN"
|
||||||
|
}
|
||||||
|
$logMessage = "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') - 启动完整命令: $($env:JDK_21)\bin\java.exe $argumentList -jar $env:MODEL_MANAGE_BIN"
|
||||||
|
Append-Utf8NoBomContent -FilePath $outputLogFile -Content $logMessage
|
||||||
|
|
||||||
|
# 启动 SpringBoot
|
||||||
|
& "$($env:JDK_21)\bin\java.exe" $argumentList -jar "$env:MODEL_MANAGE_BIN"
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# 检查并启动 MySQL 数据库
|
||||||
|
Check-With-Start-MySQL
|
||||||
|
|
||||||
|
Start-Sleep -Seconds 2
|
||||||
|
# 导入数据
|
||||||
|
Import-Script "127.0.0.1" "33306" "root" "Root@2025"
|
||||||
|
|
||||||
|
Start-Sleep -Seconds 1
|
||||||
|
# 检查 Web 运行环境
|
||||||
|
Check-Web
|
||||||
|
# 启动 Nginx 服务
|
||||||
|
Start-Web
|
||||||
|
|
||||||
|
Start-Sleep -Seconds 1
|
||||||
|
# 检查 SpringBoot 运行环境
|
||||||
|
Check-SpringBoot
|
||||||
|
# 启动 SpringBoot 服务
|
||||||
|
Start-SpringBoot
|
||||||
|
|
||||||
|
Write-Host "已启动模型"
|
||||||
|
Start-Sleep -Seconds 3
|
488
server/model_full/Execute/win10_783/startup.ps1
Normal file
488
server/model_full/Execute/win10_783/startup.ps1
Normal file
@ -0,0 +1,488 @@
|
|||||||
|
#!PowerShell
|
||||||
|
|
||||||
|
######################################################################
|
||||||
|
|
||||||
|
# Function
|
||||||
|
# CreateTime: 2025-08-06 12:52:28
|
||||||
|
# Author: Yue Jiajun
|
||||||
|
# Version: 0.1.8
|
||||||
|
|
||||||
|
# Write-Host 是否输出
|
||||||
|
# false: 打包成 exe 时,需要设置为 false
|
||||||
|
# true: 直接运行 ps1时,可以为 true
|
||||||
|
$outputWriteHost = $false
|
||||||
|
$outputLogFile = "$MAIN_PATH\startup.log"
|
||||||
|
$outputErrorFile = "$MAIN_PATH\error.log"
|
||||||
|
######################################################################
|
||||||
|
|
||||||
|
# Get current path
|
||||||
|
$MAIN_PATH = Get-Location
|
||||||
|
|
||||||
|
# Get database service name
|
||||||
|
$SERVER_NAME = $env:X_MANAGE_DB_SC
|
||||||
|
|
||||||
|
# Nginx executable name
|
||||||
|
$NGINX_EXE = "model-web.exe"
|
||||||
|
|
||||||
|
function Append-Utf8NoBomContent {
|
||||||
|
param (
|
||||||
|
[Parameter(Mandatory=$true)]
|
||||||
|
[string]$FilePath,
|
||||||
|
[Parameter(Mandatory=$true)]
|
||||||
|
[string]$Content
|
||||||
|
)
|
||||||
|
|
||||||
|
$directory = [System.IO.Path]::GetDirectoryName($FilePath)
|
||||||
|
if (-not [System.IO.Directory]::Exists($directory)) {
|
||||||
|
New-Item -ItemType Directory -Path $directory -Force | Out-Null
|
||||||
|
}
|
||||||
|
|
||||||
|
if (-not (Test-Path -Path $FilePath)) {
|
||||||
|
[System.IO.File]::WriteAllText($FilePath, "", [System.Text.Encoding]::UTF8)
|
||||||
|
}
|
||||||
|
[System.IO.File]::AppendAllText($FilePath, "$Content`r`n", [System.Text.Encoding]::UTF8)
|
||||||
|
}
|
||||||
|
|
||||||
|
function Import-Script {
|
||||||
|
param (
|
||||||
|
[string]$dbServer,
|
||||||
|
[string]$dbPort,
|
||||||
|
[string]$dbUser,
|
||||||
|
[string]$dbPassword
|
||||||
|
)
|
||||||
|
# Check whether the script folder exists in the current path
|
||||||
|
if (Test-Path -Path ".\script" -PathType Container) {
|
||||||
|
Write-Log "Found script folder, starting to process .."
|
||||||
|
|
||||||
|
# Get all subfolders
|
||||||
|
$subFolders = Get-ChildItem -Path ".\script" -Directory
|
||||||
|
|
||||||
|
if ($subFolders.Count -eq 0) {
|
||||||
|
Write-Log "There are no subfolders in the script folder, skipping processing."
|
||||||
|
exit
|
||||||
|
}
|
||||||
|
|
||||||
|
# Traverse each subfolder
|
||||||
|
foreach ($folder in $subFolders) {
|
||||||
|
Write-Log "Database connection parameters - Please modify according to the actual situation $($folder.Name)"
|
||||||
|
|
||||||
|
# Get all RAR files under this folder
|
||||||
|
$rarFiles = Get-ChildItem -Path $folder.FullName -Filter "*.rar"
|
||||||
|
|
||||||
|
if ($rarFiles.Count -eq 0) {
|
||||||
|
Write-Log "There are no SQL files in the folder $($folder.Name), skipping."
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
# Process each SQL file
|
||||||
|
foreach ($rarFile in $rarFiles) {
|
||||||
|
Write-Log "Processing file: $($rarFile.Name) (located in $($folder.Name))"
|
||||||
|
|
||||||
|
$rarName = $rarFile.BaseName
|
||||||
|
$rarDirectoryName = (Get-Item $rarFile.FullName).DirectoryName
|
||||||
|
try {
|
||||||
|
Start-Process -FilePath "rar" -ArgumentList "x -pshzyh!234 `"$($rarFile.FullName)`" `"$rarDirectoryName`"" -NoNewWindow -Wait
|
||||||
|
|
||||||
|
# Remove rar-file
|
||||||
|
if (Test-Path $rarFile.FullName) {
|
||||||
|
Remove-Item $rarFile.FullName -Force
|
||||||
|
# [debug]
|
||||||
|
# Write-Log "File deleted."
|
||||||
|
} else {
|
||||||
|
# [debug]
|
||||||
|
# Write-Log "File does not exist."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
Write-Log "Error unrar $($rarFile.Name):$_"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Traverse each subfolder
|
||||||
|
foreach ($folder in $subFolders) {
|
||||||
|
Write-Log "Database connection parameters - Please modify according to the actual situation $($folder.Name)"
|
||||||
|
|
||||||
|
# Get all SQL files under this folder
|
||||||
|
$sqlFiles = Get-ChildItem -Path $folder.FullName -Filter "*.sql"
|
||||||
|
|
||||||
|
if ($sqlFiles.Count -eq 0) {
|
||||||
|
Write-Log "There are no SQL files in the folder $($folder.Name), skipping."
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
# Process each SQL file
|
||||||
|
foreach ($sqlFile in $sqlFiles) {
|
||||||
|
Write-Log "Processing file: $($sqlFile.Name) (located in $($folder.Name))"
|
||||||
|
|
||||||
|
# Use file name as database name (without extension)
|
||||||
|
$dbName = $sqlFile.BaseName
|
||||||
|
try {
|
||||||
|
# Connect to the database and execute SQL files
|
||||||
|
Write-Log "Creating database $dbName and importing $($sqlFile.Name)"
|
||||||
|
|
||||||
|
# Here we use MySQL client as an example. If it is SQL Server, please modify it to the corresponding command
|
||||||
|
# For SQL Server, you can use sqlcmd or Invoke sqlcmd
|
||||||
|
# $command = "mysql -h$dbServer -u$dbUser -p$dbPassword -P$dbPort -e 'CREATE DATABASE IF NOT EXISTS $dbName;'"
|
||||||
|
# Invoke-Expression $command
|
||||||
|
|
||||||
|
# $command = "mysql -h$dbServer -u$dbUser -p$dbPassword -P$dbPort $dbName `< `"$($sqlFile.FullName)`""
|
||||||
|
$command = "mysql -h$dbServer -u$dbUser -p$dbPassword -P$dbPort $($folder.Name) `< `"$($sqlFile.FullName)`""
|
||||||
|
|
||||||
|
# [debug]
|
||||||
|
# Write-Log $command
|
||||||
|
|
||||||
|
# Invoke-Expression $command # ERROR
|
||||||
|
# cmd /c $command # SUCCESS, WARN: >> CategoryInfo: NotSpecified: (mysql: [Warning...an be insecure.:String) [], RemoteException
|
||||||
|
# Get-Content $sqlFile.FullName | Invoke-Expression $command # ERROR
|
||||||
|
Start-Process -FilePath "mysql" -ArgumentList "-h$dbServer -u$dbUser -p$dbPassword -P$dbPort $($folder.Name)" -RedirectStandardInput $sqlFile.FullName -NoNewWindow -Wait
|
||||||
|
|
||||||
|
# Write-Log "Successfully imported $($sqlFile.Name) into database $dbName"
|
||||||
|
Write-Log "Successfully imported $($sqlFile.Name) into database $($folder.Name)"
|
||||||
|
|
||||||
|
$date = $(Get-Date -Format "yyyy-MM-dd")
|
||||||
|
$random = randomText
|
||||||
|
$target = ".\patch\$($date)"
|
||||||
|
New-Item -Path "$target" -ItemType Directory -Force
|
||||||
|
# cmd /c rar a -pPassword -hp "target.rar" "file"
|
||||||
|
# Start-Process -FilePath "rar" -ArgumentList "a -pPassword -hp "target.rar" "file"" -NoNewWindow -Wait
|
||||||
|
# Start-Process -FilePath "rar" -ArgumentList 'a', '-pPassword', '-hpPassword', 'target.rar', 'file' -NoNewWindow -Wait
|
||||||
|
Start-Process -FilePath "rar" -ArgumentList "a -pPassword#20250810! -hp $target\$($random).rar `"$($sqlFile.FullName)`"" -NoNewWindow -Wait
|
||||||
|
|
||||||
|
# Remove script-file
|
||||||
|
if (Test-Path $sqlFile.FullName) {
|
||||||
|
Remove-Item $sqlFile.FullName -Force
|
||||||
|
# [debug]
|
||||||
|
# Write-Log "File deleted."
|
||||||
|
} else {
|
||||||
|
# [debug]
|
||||||
|
# Write-Log "File does not exist."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
Write-Log "Error importing $($sqlFile.Name):$_"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Log "All script processing has been completed."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function Go-Home {
|
||||||
|
if($outputWriteHost) {
|
||||||
|
Write-Host ""
|
||||||
|
Write-Host "Exit ..."
|
||||||
|
}
|
||||||
|
$logMessage = "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') - 任务执行完成"
|
||||||
|
Append-Utf8NoBomContent -FilePath $outputLogFile -Content $logMessage
|
||||||
|
Start-Sleep -Seconds 5
|
||||||
|
exit 0
|
||||||
|
}
|
||||||
|
|
||||||
|
function Usage-MySQL {
|
||||||
|
if($outputWriteHost) {
|
||||||
|
Write-Host "ERROR: Please configure value in the system environment variable."
|
||||||
|
Write-Host "env: - X_MANAGE_DB_EXE"
|
||||||
|
Write-Host " - X_MANAGE_DB_COF"
|
||||||
|
Write-Host "skip database"
|
||||||
|
Write-Host ""
|
||||||
|
}
|
||||||
|
pause
|
||||||
|
Go-Home
|
||||||
|
}
|
||||||
|
|
||||||
|
function Usage-SpringBoot {
|
||||||
|
if($outputWriteHost) {
|
||||||
|
Write-Host "ERROR: Please configure `"JDK_21`" in the system environment variable."
|
||||||
|
}
|
||||||
|
pause
|
||||||
|
Go-Home
|
||||||
|
}
|
||||||
|
|
||||||
|
function Install-MySQL-Server {
|
||||||
|
# Check required environment variables
|
||||||
|
if (-not $env:X_MANAGE_DB_EXE) {
|
||||||
|
if($outputWriteHost) {
|
||||||
|
Write-Host "Error: Missing parameter! {X_MANAGE_DB_EXE}" | Out-File "error.log" -Append
|
||||||
|
}
|
||||||
|
Usage-MySQL
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (-not (Test-Path $env:X_MANAGE_DB_EXE)) {
|
||||||
|
if($outputWriteHost) {
|
||||||
|
Write-Host "Error: Missing parameter! {X_MANAGE_DB_EXE}" | Out-File "error.log" -Append
|
||||||
|
}
|
||||||
|
Usage-MySQL
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Host "exe: $($env:X_MANAGE_DB_EXE)"
|
||||||
|
$DB_EXEC = $env:X_MANAGE_DB_EXE
|
||||||
|
|
||||||
|
if (-not $env:X_MANAGE_DB_COF) {
|
||||||
|
if($outputWriteHost) {
|
||||||
|
Write-Host "Error: Missing parameter! {X_MANAGE_DB_COF}" | Out-File "error.log" -Append
|
||||||
|
}
|
||||||
|
Usage-MySQL
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (-not (Test-Path $env:X_MANAGE_DB_COF)) {
|
||||||
|
if($outputWriteHost) {
|
||||||
|
Write-Host "Error: Missing parameter! {X_MANAGE_DB_COF}" | Out-File "error.log" -Append
|
||||||
|
}
|
||||||
|
Usage-MySQL
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if($outputWriteHost) {
|
||||||
|
Write-Host "ini: $($env:X_MANAGE_DB_COF)"
|
||||||
|
}
|
||||||
|
$DB_CONF = $env:X_MANAGE_DB_COF
|
||||||
|
|
||||||
|
# Install MySQL service
|
||||||
|
& $DB_EXEC --install $SERVER_NAME --defaults-file="$DB_CONF"
|
||||||
|
|
||||||
|
# Configure service to start automatically
|
||||||
|
sc.exe config $SERVER_NAME start= auto
|
||||||
|
|
||||||
|
# Wait for service registration
|
||||||
|
Start-Sleep -Seconds 1
|
||||||
|
|
||||||
|
# Start the service
|
||||||
|
Start-Service -Name $SERVER_NAME
|
||||||
|
|
||||||
|
# Wait for service to start
|
||||||
|
Start-Sleep -Seconds 1
|
||||||
|
}
|
||||||
|
|
||||||
|
function Check-With-Start-MySQL {
|
||||||
|
# Check if service exists
|
||||||
|
$service = Get-Service -Name $SERVER_NAME -ErrorAction SilentlyContinue
|
||||||
|
|
||||||
|
if ($service) {
|
||||||
|
# Service exists, check if running
|
||||||
|
if ($service.Status -eq "Running") {
|
||||||
|
if($outputWriteHost) {
|
||||||
|
Write-Host "database ok."
|
||||||
|
}
|
||||||
|
$logMessage = "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') - 数据已运行..."
|
||||||
|
Append-Utf8NoBomContent -FilePath $outputLogFile -Content $logMessage
|
||||||
|
} else {
|
||||||
|
# Start the service if not running
|
||||||
|
if($outputWriteHost) {
|
||||||
|
Write-Host "start up ..."
|
||||||
|
}
|
||||||
|
$logMessage = "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') - 启动数据库中..."
|
||||||
|
Append-Utf8NoBomContent -FilePath $outputLogFile -Content $logMessage
|
||||||
|
Start-Service -Name $SERVER_NAME
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
# Install MySQL service
|
||||||
|
Install-MySQL-Server
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function Check-Web {
|
||||||
|
# 检查
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function Check-SpringBoot {
|
||||||
|
if (-not $env:JDK_21) {
|
||||||
|
if (Test-Path "$MAIN_PATH\jre\bin\java.exe") {
|
||||||
|
$env:JDK_21 = "$MAIN_PATH\jre"
|
||||||
|
if($outputWriteHost) {
|
||||||
|
Write-Host "ONESELF"
|
||||||
|
}
|
||||||
|
$logMessage = "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') - JDK_21 环境变量不存在,默认生效: $env:JDK_21"
|
||||||
|
Append-Utf8NoBomContent -FilePath $outputLogFile -Content $logMessage
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (-not $env:JDK_21) {
|
||||||
|
Usage-SpringBoot
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (-not $env:MODEL_MANAGE_DB_SERVER) {
|
||||||
|
$env:MODEL_MANAGE_DB_SERVER = "127.0.0.1"
|
||||||
|
$logMessage = "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') - MODEL_MANAGE_DB_SERVER 环境变量不存在,默认生效: $env:MODEL_MANAGE_DB_SERVER"
|
||||||
|
Append-Utf8NoBomContent -FilePath $outputLogFile -Content $logMessage
|
||||||
|
}
|
||||||
|
|
||||||
|
if (-not $env:MODEL_MANAGE_DB_PORT) {
|
||||||
|
$env:MODEL_MANAGE_DB_PORT = "3306"
|
||||||
|
$logMessage = "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') - MODEL_MANAGE_DB_PORT 环境变量不存在,默认生效: $env:MODEL_MANAGE_DB_PORT"
|
||||||
|
Append-Utf8NoBomContent -FilePath $outputLogFile -Content $logMessage
|
||||||
|
}
|
||||||
|
|
||||||
|
if (-not $env:MODEL_MANAGE_BIN) {
|
||||||
|
$env:MODEL_MANAGE_BIN = "$MAIN_PATH\bin\demo-0.0.1.jar"
|
||||||
|
$logMessage = "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') - MODEL_MANAGE_BIN 环境变量不存在,默认生效: $env:MODEL_MANAGE_BIN"
|
||||||
|
Append-Utf8NoBomContent -FilePath $outputLogFile -Content $logMessage
|
||||||
|
if (-not $env:MODEL_MANAGE_BIN) {
|
||||||
|
if($outputWriteHost) {
|
||||||
|
Write-Host "ERROR: Missing executable jar"
|
||||||
|
}
|
||||||
|
$logMessage = "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') - 缺少可执行的 jar"
|
||||||
|
Append-Utf8NoBomContent -FilePath $outputLogFile -Content $logMessage
|
||||||
|
pause
|
||||||
|
Go-Home
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if($outputWriteHost) {
|
||||||
|
Write-Host "jdk ok."
|
||||||
|
Write-Host ""
|
||||||
|
}
|
||||||
|
Start-Sleep -Seconds 1
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function Start-Web {
|
||||||
|
|
||||||
|
Set-Location "$MAIN_PATH\web"
|
||||||
|
if($outputWriteHost) {
|
||||||
|
Write-Host "Start Web ..."
|
||||||
|
}
|
||||||
|
$logMessage = "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') - 准备Web启动..."
|
||||||
|
Append-Utf8NoBomContent -FilePath $outputLogFile -Content $logMessage
|
||||||
|
|
||||||
|
Get-Process -Name $NGINX_EXE.Replace(".exe", "") -ErrorAction SilentlyContinue | Stop-Process -Force
|
||||||
|
|
||||||
|
$NGINX_PATH = $NGINX_EXE
|
||||||
|
if (-not $NGINX_PATH) {
|
||||||
|
# $NGINX_PATH = "$MAIN_PATH\nginx.exe"
|
||||||
|
$NGINX_PATH = "nginx.exe"
|
||||||
|
if (-not $NGINX_PATH) {
|
||||||
|
if($outputWriteHost) {
|
||||||
|
Write-Host "ERROR: Missing executable web."
|
||||||
|
}
|
||||||
|
pause
|
||||||
|
Go-Home
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if($outputWriteHost) {
|
||||||
|
Write-Host "$NGINX_PATH"
|
||||||
|
}
|
||||||
|
$logMessage = "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') - Web生效可执行器: $NGINX_PATH"
|
||||||
|
Append-Utf8NoBomContent -FilePath $outputLogFile -Content $logMessage
|
||||||
|
|
||||||
|
# $NGINX_CONFIG = "$MAIN_PATH\conf\web.conf"
|
||||||
|
$NGINX_CONFIG = "conf\web.conf"
|
||||||
|
if (-not $NGINX_CONFIG) {
|
||||||
|
# $NGINX_CONFIG = "$MAIN_PATH\conf\nginx.conf"
|
||||||
|
$NGINX_CONFIG = "conf\nginx.conf"
|
||||||
|
if (-not $NGINX_CONFIG) {
|
||||||
|
if($outputWriteHost) {
|
||||||
|
Write-Host "ERROR: Missing web config"
|
||||||
|
}
|
||||||
|
pause
|
||||||
|
Go-Home
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if($outputWriteHost) {
|
||||||
|
Write-Host "$NGINX_CONFIG"
|
||||||
|
}
|
||||||
|
$logMessage = "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') - Web配置生效文件: $NGINX_CONFIG"
|
||||||
|
Append-Utf8NoBomContent -FilePath $outputLogFile -Content $logMessage
|
||||||
|
|
||||||
|
$vbsContent = @"
|
||||||
|
Set UAC = CreateObject("Shell.Application")
|
||||||
|
Set WshShell = CreateObject("WScript.Shell")
|
||||||
|
|
||||||
|
On Error Resume Next
|
||||||
|
Set fso = CreateObject("Scripting.FileSystemObject")
|
||||||
|
Set tempFile = fso.OpenTextFile("%SystemRoot%\System32\config\systemprofile", 1)
|
||||||
|
If Err.Number = 0 Then
|
||||||
|
WshShell.Run "$NGINX_PATH -c $NGINX_CONFIG", 0, False
|
||||||
|
Else
|
||||||
|
UAC.ShellExecute "$NGINX_PATH", "-c $NGINX_CONFIG", "", "runas", 0
|
||||||
|
End If
|
||||||
|
"@
|
||||||
|
|
||||||
|
# 以 ANSI 写入文件 temp.vbs,vbs 脚本不能使用 utf-8
|
||||||
|
$vbsContent | Out-File -FilePath "$MAIN_PATH\web\temp.vbs" -Encoding ASCII
|
||||||
|
if($outputWriteHost) {
|
||||||
|
Write-Host "Build temporary startup script web."
|
||||||
|
}
|
||||||
|
|
||||||
|
# 运行 vbs 并等待结束
|
||||||
|
# Start-Process "cscript.exe" -ArgumentList "//nologo temp.vbs" -Wait
|
||||||
|
|
||||||
|
# 不等待,执行下一条命令,Nginx 本身是持续性窗口,等待会导致阻塞
|
||||||
|
Start-Process "cscript.exe" -ArgumentList "//nologo temp.vbs"
|
||||||
|
|
||||||
|
Start-Sleep -Seconds 1
|
||||||
|
Remove-Item "temp.vbs" -Force
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function Start-SpringBoot {
|
||||||
|
|
||||||
|
# 准备启动后台服务
|
||||||
|
Set-Location $MAIN_PATH
|
||||||
|
if($outputWriteHost) {
|
||||||
|
Write-Host "Start Server ..."
|
||||||
|
}
|
||||||
|
$logMessage = "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') - 准备SpringBoot启动..."
|
||||||
|
Append-Utf8NoBomContent -FilePath $outputLogFile -Content $logMessage
|
||||||
|
|
||||||
|
# jvm启动参数
|
||||||
|
# 指定环境变量 MODEL_MANAGE_DB_SERVER
|
||||||
|
# 指定环境变量 MODEL_MANAGE_DB_PORT
|
||||||
|
# 追加自定义JVM参数 MODEL_VM_PARAMS
|
||||||
|
$arguments = "-Dspring.profiles.active=dev,mysql -Dmybatis-flex.datasource.ds1.password=Wfbke8!LeMY5Fwwe -Dproject.database-ip=$env:MODEL_MANAGE_DB_SERVER -Dproject.database-port=$env:MODEL_MANAGE_DB_PORT $env:MODEL_VM_PARAMS"
|
||||||
|
$logMessage = "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') - 启动JVM参数: $arguments"
|
||||||
|
Append-Utf8NoBomContent -FilePath $outputLogFile -Content $logMessage
|
||||||
|
$argumentList = $arguments -split " -"
|
||||||
|
$argumentList = @($argumentList[0]) + ($argumentList[1..($argumentList.Length-1)] | ForEach-Object { "-$_" })
|
||||||
|
if($outputWriteHost) {
|
||||||
|
Write-Host "$($env:JDK_21)\bin\java.exe" $argumentList -jar "$env:MODEL_MANAGE_BIN"
|
||||||
|
}
|
||||||
|
$logMessage = "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') - 启动完整命令: $($env:JDK_21)\bin\java.exe $argumentList -jar $env:MODEL_MANAGE_BIN"
|
||||||
|
Append-Utf8NoBomContent -FilePath $outputLogFile -Content $logMessage
|
||||||
|
|
||||||
|
# 启动 SpringBoot
|
||||||
|
$argumentList += "-jar"
|
||||||
|
$argumentList += "`"$env:MODEL_MANAGE_BIN`""
|
||||||
|
$process = Start-Process `
|
||||||
|
-FilePath "$($env:JDK_21)\bin\java.exe" `
|
||||||
|
-ArgumentList $argumentList `
|
||||||
|
-WindowStyle Hidden `
|
||||||
|
-RedirectStandardOutput "NUL" `
|
||||||
|
-RedirectStandardError "NUL_ERR" `
|
||||||
|
-PassThru
|
||||||
|
|
||||||
|
if ($process) {
|
||||||
|
Write-Host "进程已启动,PID: $($process.Id)"
|
||||||
|
} else {
|
||||||
|
Write-Host "进程启动失败!"
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# 检查并启动 MySQL 数据库
|
||||||
|
Check-With-Start-MySQL
|
||||||
|
|
||||||
|
Start-Sleep -Seconds 2
|
||||||
|
# 导入数据
|
||||||
|
Import-Script "127.0.0.1" "33306" "root" "Root@2025"
|
||||||
|
|
||||||
|
Start-Sleep -Seconds 1
|
||||||
|
# 检查 Web 运行环境
|
||||||
|
Check-Web
|
||||||
|
# 启动 Nginx 服务
|
||||||
|
Start-Web
|
||||||
|
|
||||||
|
Start-Sleep -Seconds 1
|
||||||
|
# 检查 SpringBoot 运行环境
|
||||||
|
Check-SpringBoot
|
||||||
|
# 启动 SpringBoot 服务
|
||||||
|
Start-SpringBoot
|
||||||
|
|
||||||
|
Write-Host "已启动模型"
|
||||||
|
Start-Sleep -Seconds 3
|
Loading…
x
Reference in New Issue
Block a user