summaryrefslogtreecommitdiff
path: root/scripts/Restart-PublishedServer.ps1
blob: 58dd928f3f3f108a245dafee85300f114b0b0a2d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
param(
    [string]$BundlePath = 'build\Release\publish\agent-sandbox-mcp-1.0.0-win-x64',
    [switch]$StopOnly
)

$ErrorActionPreference = 'Stop'
$repository = (Resolve-Path (Join-Path $PSScriptRoot '..')).Path
$bundle = [IO.Path]::GetFullPath((Join-Path $repository $BundlePath))
$publishRoot = [IO.Path]::GetFullPath((Join-Path $repository 'build\Release\publish'))
if (-not $bundle.StartsWith($publishRoot + [IO.Path]::DirectorySeparatorChar, [StringComparison]::OrdinalIgnoreCase)) {
    throw 'BundlePath must remain inside build\Release\publish.'
}
$agent = Join-Path $bundle 'agent-mcp.exe'
$configuration = Join-Path $bundle 'agent.yaml'

$matching = Get-Process -Name 'agent-mcp' -ErrorAction SilentlyContinue | Where-Object {
    try { [IO.Path]::GetFullPath($_.Path).Equals($agent, [StringComparison]::OrdinalIgnoreCase) }
    catch { $false }
}
foreach ($process in $matching) {
    Stop-Process -Id $process.Id -Force
    $process.WaitForExit()
    Write-Output "Stopped published agent-mcp PID $($process.Id)."
}
if ($StopOnly) { exit 0 }
if (-not (Test-Path -LiteralPath $agent) -or -not (Test-Path -LiteralPath $configuration)) {
    throw 'Published agent-mcp executable or configuration is missing.'
}
$started = Start-Process -FilePath $agent -ArgumentList @('serve', '--config', $configuration) -WorkingDirectory $bundle -WindowStyle Hidden -PassThru
Write-Output "Started published agent-mcp PID $($started.Id)."