Files
ProxyPilot/scripts/windows/start-cliproxy.ps1
T

62 lines
2.1 KiB
PowerShell

Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop"
function Get-RepoRoot {
return (Resolve-Path (Join-Path $PSScriptRoot "..\\..")).Path
}
function Ensure-Dir([string]$Path) {
if (-not (Test-Path -LiteralPath $Path)) {
New-Item -ItemType Directory -Path $Path | Out-Null
}
}
$repoRoot = Get-RepoRoot
$defaultExePath = Join-Path $repoRoot "bin\\cliproxyapi.exe"
$latestExePath = Join-Path $repoRoot "bin\\cliproxyapi-latest.exe"
$exePath = if (Test-Path -LiteralPath $latestExePath) { $latestExePath } else { $defaultExePath }
$configPath = Join-Path $repoRoot "config.yaml"
$logsDir = Join-Path $repoRoot "logs"
Ensure-Dir $logsDir
$stdoutLog = Join-Path $logsDir "cliproxyapi.out.log"
$stderrLog = Join-Path $logsDir "cliproxyapi.err.log"
if (-not (Test-Path -LiteralPath $exePath)) {
throw "Binary not found: $exePath. Build it with: go build -o bin\\cliproxyapi.exe .\\cmd\\server (or: scripts\\build-cliproxyapi.ps1)."
}
if (-not (Test-Path -LiteralPath $configPath)) {
throw "Config not found: $configPath"
}
function Get-ConfigPort([string]$Path) {
try {
$line = Get-Content -LiteralPath $Path | Where-Object { $_ -match '^\s*port:\s*\d+\s*$' } | Select-Object -First 1
if ($line -match '(\d+)') { return [int]$Matches[1] }
} catch {}
return 8318
}
$port = Get-ConfigPort $configPath
$existing = Get-NetTCPConnection -LocalPort $port -State Listen -ErrorAction SilentlyContinue | Select-Object -First 1
if ($existing) {
Write-Warning "Port $port is already in use (PID $($existing.OwningProcess))."
Write-Host "If this is CLIProxyAPI, run: powershell -NoProfile -ExecutionPolicy Bypass -File .\\scripts\\restart-cliproxy.ps1"
return
}
Write-Host "Starting CLIProxyAPI..."
Write-Host " exe: $exePath"
Write-Host " config: $configPath"
Write-Host " logs: $logsDir"
Start-Process -FilePath $exePath `
-ArgumentList @("-config", $configPath) `
-WorkingDirectory $repoRoot `
-WindowStyle Hidden `
-RedirectStandardOutput $stdoutLog `
-RedirectStandardError $stderrLog | Out-Null
Write-Host "Started. Tail logs:"
Write-Host " Get-Content -Wait $stdoutLog"