22 lines
1.3 KiB
PowerShell
22 lines
1.3 KiB
PowerShell
|
|
$ErrorActionPreference = 'Stop'
|
||
|
|
$taskRoot = Split-Path -Parent $PSScriptRoot
|
||
|
|
$taskSimulatorStatus = Join-Path $taskRoot '.local/simulator/status.json'
|
||
|
|
if (Test-Path -LiteralPath $taskSimulatorStatus) {
|
||
|
|
$taskSimulatorState = Get-Content -LiteralPath $taskSimulatorStatus -Raw | ConvertFrom-Json
|
||
|
|
if ($taskSimulatorState.running) {
|
||
|
|
& (Join-Path $PSScriptRoot 'manage-simulator.ps1') -Action stop
|
||
|
|
}
|
||
|
|
}
|
||
|
|
$taskPidPath = Join-Path $taskRoot '.local/backend.pid'
|
||
|
|
if (-not (Test-Path -LiteralPath $taskPidPath)) { Write-Output '没有本机预启动实例的 PID 记录。'; exit 0 }
|
||
|
|
$taskBackendPid = [int](Get-Content -LiteralPath $taskPidPath -Raw)
|
||
|
|
$taskProcess = Get-CimInstance Win32_Process -Filter "ProcessId = $taskBackendPid"
|
||
|
|
if (-not $taskProcess) { Write-Output '记录的后端进程已退出。'; exit 0 }
|
||
|
|
$taskExpectedJar = (Join-Path $taskRoot 'am-backend/yudao-server/target/yudao-server.jar').Replace('/', '\')
|
||
|
|
$taskCommandLine = $taskProcess.CommandLine.Replace('/', '\')
|
||
|
|
if ($taskProcess.Name -ne 'java.exe' -or -not $taskCommandLine.Contains($taskExpectedJar, [System.StringComparison]::OrdinalIgnoreCase)) {
|
||
|
|
throw 'PID 已被其他进程使用,未停止任何进程。'
|
||
|
|
}
|
||
|
|
Stop-Process -Id $taskBackendPid
|
||
|
|
Write-Output 'AM FreeScan 本机预启动后端已停止。'
|