Anrn-12B-R1 / rollback-llama-bootstrap.ps1
chirs345678's picture
Add files using upload-large-folder tool
4e6526a verified
Raw
History Blame Contribute Delete
2.08 kB
$ErrorActionPreference = 'Stop'
$Root = $PSScriptRoot
$Baseline = Join-Path $Root 'rollback\llama-bootstrap-baseline'
$Listener = Get-NetTCPConnection -State Listen -LocalPort 8091 -ErrorAction SilentlyContinue | Select-Object -First 1
if ($Listener) {
$Owner = Get-CimInstance Win32_Process -Filter "ProcessId=$($Listener.OwningProcess)"
if ($Owner.Name -eq 'llama-server.exe') {
Stop-Process -Id $Listener.OwningProcess -Force
Wait-Process -Id $Listener.OwningProcess -Timeout 30 -ErrorAction SilentlyContinue
}
}
$Disabled = Join-Path $Root ('rollback\llama-bootstrap-disabled-' + (Get-Date -Format 'yyyyMMdd-HHmmss'))
New-Item -ItemType Directory -Path $Disabled -Force | Out-Null
$RuntimeDirs = @(Get-ChildItem -LiteralPath $Root -Directory -Filter 'llama-runtime*' -ErrorAction SilentlyContinue)
foreach ($RuntimeDir in $RuntimeDirs) {
$Resolved = [IO.Path]::GetFullPath($RuntimeDir.FullName)
if (-not $Resolved.StartsWith(([IO.Path]::GetFullPath($Root) + [IO.Path]::DirectorySeparatorChar), [StringComparison]::OrdinalIgnoreCase)) {
throw "Unsafe rollback target: $Resolved"
}
Move-Item -LiteralPath $Resolved -Destination $Disabled -Force
}
foreach ($Name in @('llama-model','llama-runtime-state.json','llama-service-state.json','llama-server.stdout.log','llama-server.stderr.log','Start-Llama-Service.bat','Stop-Llama-Service.bat','llama-bootstrap.ps1')) {
$Target = Join-Path $Root $Name
if (Test-Path -LiteralPath $Target) {
$Resolved = [IO.Path]::GetFullPath($Target)
if (-not $Resolved.StartsWith(([IO.Path]::GetFullPath($Root) + [IO.Path]::DirectorySeparatorChar), [StringComparison]::OrdinalIgnoreCase)) {
throw "Unsafe rollback target: $Resolved"
}
Move-Item -LiteralPath $Target -Destination $Disabled -Force
}
}
foreach ($Name in @('package.json','README.md')) {
Copy-Item -LiteralPath (Join-Path $Baseline $Name) -Destination (Join-Path $Root $Name) -Force
}
Write-Output 'package llama bootstrap rolled back to the verified native-only baseline'