tower-learns-you / scripts /Stop-LlamaServer.ps1
vknt's picture
Deploy The Tower Learns You (custom gr.Server frontend, hf_inference + mock fallback)
22a027e verified
Raw
History Blame Contribute Delete
1.35 kB
[CmdletBinding()]
param()
$ErrorActionPreference = "Stop"
$runtimeRoot = (Resolve-Path (Join-Path $PSScriptRoot "..\.local\llama.cpp")).Path
$pidPath = Join-Path $runtimeRoot "server.pid"
if (-not (Test-Path $pidPath)) {
Write-Output "No recorded llama.cpp server process."
exit 0
}
$recordedPid = Get-Content $pidPath -Raw
if ([string]::IsNullOrWhiteSpace($recordedPid)) {
Write-Output "No recorded llama.cpp server process."
exit 0
}
$recordedPid = $recordedPid.Trim()
$serverPid = [int]$recordedPid
$process = Get-Process -Id $serverPid -ErrorAction SilentlyContinue
if (-not $process) {
Set-Content -LiteralPath $pidPath -Value "" -Encoding ASCII -NoNewline
Write-Output "Removed stale llama.cpp PID file."
exit 0
}
$expectedRoot = (Resolve-Path $runtimeRoot).Path
$processPath = $process.Path
if (
$process.ProcessName -ne "llama-server" -or
-not $processPath.StartsWith($expectedRoot, [System.StringComparison]::OrdinalIgnoreCase)
) {
throw "PID $serverPid is not the expected repository-owned llama-server process; refusing to stop it."
}
Stop-Process -Id $serverPid -Force
Wait-Process -Id $serverPid -Timeout 15 -ErrorAction SilentlyContinue
Set-Content -LiteralPath $pidPath -Value "" -Encoding ASCII -NoNewline
Write-Output "Stopped llama-server PID $serverPid."