Files
AIGame/Tools/start_local_server.ps1
T

37 lines
1.7 KiB
PowerShell

$ErrorActionPreference = 'Stop'
$taskRoot = Split-Path -Parent $PSScriptRoot
$taskServer = Join-Path $taskRoot 'AIServer/build/Release/aiserver.exe'
$taskData = Join-Path $taskRoot 'AIServer/data/aiserver.db'
$taskLogs = Join-Path $taskRoot 'Tools/output'
try {
$taskHealth = Invoke-RestMethod -Uri 'http://127.0.0.1:8080/health' -TimeoutSec 2
if ($taskHealth.ok -eq $true -and $taskHealth.service -eq 'aiserver') {
Write-Output 'AIServer already healthy at http://127.0.0.1:8080'
exit 0
}
} catch { }
if (-not (Test-Path -LiteralPath $taskServer)) {
throw 'Build AIServer first: cmake --build AIServer/build --config Release'
}
New-Item -ItemType Directory -Path $taskLogs -Force | Out-Null
$taskProcess = Start-Process -FilePath $taskServer -ArgumentList @(
'--host', '127.0.0.1', '--port', '8080', '--db', $taskData, '--daemon'
) -WorkingDirectory (Join-Path $taskRoot 'AIServer') -WindowStyle Hidden -PassThru `
-RedirectStandardOutput (Join-Path $taskLogs 'aiserver-local.stdout.log') `
-RedirectStandardError (Join-Path $taskLogs 'aiserver-local.stderr.log')
for ($taskAttempt = 0; $taskAttempt -lt 15; $taskAttempt++) {
Start-Sleep -Milliseconds 200
if ($taskProcess.HasExited) { throw 'AIServer exited; inspect Tools/output/aiserver-local.stderr.log' }
try {
$taskHealth = Invoke-RestMethod -Uri 'http://127.0.0.1:8080/health' -TimeoutSec 1
if ($taskHealth.ok -eq $true -and $taskHealth.service -eq 'aiserver') {
Write-Output "AIServer healthy at http://127.0.0.1:8080 (PID $($taskProcess.Id))"
exit 0
}
} catch { }
}
throw 'AIServer did not become healthy at http://127.0.0.1:8080'