保存模拟部署迁移与最新构建校验阶段成果
Security Checks / security (push) Waiting to run

This commit is contained in:
xuans committed 2026-09-08 18:33:21 +08:00
1 parent 519e2b4a5f
commit d7837de561
45 files changed
+1588 -109

No files matched your search

+35
View File
@@ -0,0 +1,35 @@
param([switch]$Restart)
$ErrorActionPreference = 'Stop'
$root = Split-Path -Parent $PSScriptRoot
$runtime = Join-Path $root 'yunx-test'
$binary = Join-Path $runtime 'smail.exe'
& node (Join-Path $PSScriptRoot 'check-runtime.mjs')
if ($LASTEXITCODE -ne 0) { throw '模拟部署目录未准备完成' }
if ($Restart) {
Get-CimInstance Win32_Process | Where-Object { $_.ExecutablePath -eq $binary } | ForEach-Object {
Stop-Process -Id $_.ProcessId -ErrorAction Stop
}
Start-Sleep -Seconds 2
}
& (Join-Path $PSScriptRoot 'deploy-runtime.ps1')
& node (Join-Path $PSScriptRoot 'build-state.mjs') verify --deployed
if ($LASTEXITCODE -ne 0) { throw '运行包不是最新源码的构建结果' }
$previous = @{}
foreach ($name in @('SMAIL_ROOT', 'SMAIL_HTTP_PORT_OVERRIDE', 'SMAIL_HTTP_TLS_MODE_OVERRIDE', 'setup_port', 'SMAIL_DEV_DISABLE_ADMIN_RESET')) {
$previous[$name] = [Environment]::GetEnvironmentVariable($name, 'Process')
[Environment]::SetEnvironmentVariable($name, $null, 'Process')
}
try {
$env:SMAIL_ROOT = $runtime
$stamp = Get-Date -Format 'yyyyMMdd-HHmmss-fff'
$process = Start-Process -FilePath $binary -WorkingDirectory $runtime -WindowStyle Hidden -PassThru `
-RedirectStandardOutput (Join-Path $runtime "log\production-$stamp.stdout.log") `
-RedirectStandardError (Join-Path $runtime "log\production-$stamp.stderr.log")
Start-Sleep -Seconds 3
$process.Refresh()
if ($process.HasExited) { throw '生产模拟启动失败,请检查 yunx-test/log;不会自动豁免管理员恢复通道保护' }
Write-Output "生产模拟已启动:$($process.Id),使用嵌入前端和 yunx-test 配置,管理员恢复通道保持保护。"
} finally {
foreach ($name in $previous.Keys) { [Environment]::SetEnvironmentVariable($name, $previous[$name], 'Process') }
}