81 lines
3.2 KiB
PowerShell
81 lines
3.2 KiB
PowerShell
# 在应用机启动新系统主账 8180(不碰现网 8080)
|
||
$ErrorActionPreference = 'Stop'
|
||
$Root = 'E:\wwwroot\inquiry-new'
|
||
$Jar = Join-Path $Root 'jeecg-system-start-3.5.3.jar'
|
||
$LogDir = Join-Path $Root 'logs'
|
||
$SqlDir = Join-Path $Root 'sql'
|
||
New-Item -ItemType Directory -Force -Path $Root,$LogDir,$SqlDir | Out-Null
|
||
|
||
# 加载 E:\wwwroot\.env(不打印密钥)
|
||
Get-Content 'E:\wwwroot\.env' | ForEach-Object {
|
||
$line = $_.Trim()
|
||
if (-not $line -or $line.StartsWith('#')) { return }
|
||
$i = $line.IndexOf('=')
|
||
if ($i -lt 1) { return }
|
||
$k = $line.Substring(0, $i).Trim()
|
||
$v = $line.Substring($i + 1).Trim()
|
||
if ($v.StartsWith('"') -and $v.EndsWith('"')) { $v = $v.Substring(1, $v.Length - 2) }
|
||
[Environment]::SetEnvironmentVariable($k, $v, 'Process')
|
||
Set-Item -Path "Env:$k" -Value $v
|
||
}
|
||
|
||
# Jeecg Redis 口令:从 REDIS_URL 解析(redis://:pass@host:port/db)
|
||
if (-not $env:YTD_REDIS_PASSWORD -and $env:REDIS_URL) {
|
||
if ($env:REDIS_URL -match 'redis://:([^@]+)@') {
|
||
$env:YTD_REDIS_PASSWORD = $Matches[1]
|
||
} elseif ($env:REDIS_URL -match 'redis://[^:]+:([^@]+)@') {
|
||
$env:YTD_REDIS_PASSWORD = $Matches[1]
|
||
}
|
||
}
|
||
if (-not $env:YTD_REDIS_HOST) { $env:YTD_REDIS_HOST = '127.0.0.1' }
|
||
# 本机 Redis 监听 127.0.0.1
|
||
$env:YTD_REDIS_HOST = '127.0.0.1'
|
||
$env:LEDGER_PORT = '8180'
|
||
|
||
Write-Host "MYSQL_DB=$env:MYSQL_DB MYSQL_HOST=$env:MYSQL_HOST LEDGER_PORT=$env:LEDGER_PORT REDIS_HOST=$env:YTD_REDIS_HOST"
|
||
|
||
$Mysql = 'C:\yutongda\tools\mysql-8.0.39-winx64\bin\mysql.exe'
|
||
if (-not (Test-Path $Mysql)) { throw "mysql client missing: $Mysql" }
|
||
if (-not (Test-Path $Jar)) { throw "jar missing: $Jar" }
|
||
|
||
# 导入业务 SQL(可重复)
|
||
function Import-Sql([string]$file) {
|
||
if (-not (Test-Path $file)) { Write-Host "skip missing $file"; return }
|
||
Write-Host "import $file"
|
||
& $Mysql -h $env:MYSQL_HOST -P $env:MYSQL_PORT -u $env:MYSQL_USER "-p$env:MYSQL_PASSWORD" --default-character-set=utf8mb4 $env:MYSQL_DB -e "source $($file.Replace('\','/'))"
|
||
if ($LASTEXITCODE -ne 0) { throw "sql import failed: $file code=$LASTEXITCODE" }
|
||
}
|
||
|
||
Import-Sql (Join-Path $SqlDir 'inquiry_admin_v1.sql')
|
||
Import-Sql (Join-Path $SqlDir 'inquiry_admin_menu_seed_v1.sql')
|
||
|
||
# 若已有 8180 进程则先停(仅本目录 jar)
|
||
Get-CimInstance Win32_Process -Filter "Name='java.exe'" | ForEach-Object {
|
||
if ($_.CommandLine -and $_.CommandLine -like '*inquiry-new*jeecg-system-start*') {
|
||
Write-Host "stop pid=$($_.ProcessId)"
|
||
Stop-Process -Id $_.ProcessId -Force -ErrorAction SilentlyContinue
|
||
}
|
||
}
|
||
|
||
$Java = 'C:\yutongda\tools\jdk8\bin\java.exe'
|
||
$Out = Join-Path $LogDir 'stdout.log'
|
||
$Err = Join-Path $LogDir 'stderr.log'
|
||
$arg = @(
|
||
'-jar', $Jar,
|
||
'--spring.profiles.active=inquiry',
|
||
"--server.port=$env:LEDGER_PORT"
|
||
)
|
||
Write-Host "starting $Java $($arg -join ' ')"
|
||
$p = Start-Process -FilePath $Java -ArgumentList $arg -WorkingDirectory $Root -RedirectStandardOutput $Out -RedirectStandardError $Err -PassThru -WindowStyle Hidden
|
||
Write-Host "started pid=$($p.Id)"
|
||
Start-Sleep -Seconds 8
|
||
# 健康探测
|
||
try {
|
||
$r = Invoke-WebRequest -Uri "http://127.0.0.1:8180/jeecgboot/" -UseBasicParsing -TimeoutSec 10
|
||
Write-Host "health status=$($r.StatusCode)"
|
||
} catch {
|
||
Write-Host "health pending: $($_.Exception.Message)"
|
||
Write-Host '--- stderr tail ---'
|
||
if (Test-Path $Err) { Get-Content $Err -Tail 40 }
|
||
}
|