deerflow-code/scripts/start-backend.ps1
2026-09-07 18:24:55 +08:00

43 lines
1.8 KiB
PowerShell

. "$PSScriptRoot\env.ps1"
$PidFile = Join-Path $PidDir "backend.pid"
$LogFile = Join-Path $LogDir "backend.log"
if (Test-PidRunning $PidFile) {
$existingPid = Get-Content -LiteralPath $PidFile | Select-Object -First 1
Write-Host "Backend is already running (pid $existingPid)."
Write-Host "URL: $BackendPublicBaseUrl"
exit 0
}
if (-not (Test-Path -LiteralPath $BackendPython)) {
throw "Backend Python not found: $BackendPython. Run uv sync in offline-backend-20260512/backend first."
}
Remove-Item -LiteralPath $PidFile -Force -ErrorAction SilentlyContinue
New-Item -ItemType Directory -Force -Path $BackendVendorDir | Out-Null
Write-Host "Starting backend..."
Write-Host "Log: $LogFile"
$RunnerFile = Join-Path $RuntimeDir "run-backend.ps1"
$runner = @"
`$ErrorActionPreference = "Continue"
Set-Location -LiteralPath $(ConvertTo-PSLiteral $BackendDir)
`$env:GATEWAY_CORS_ORIGINS = $(ConvertTo-PSLiteral $GatewayCorsOrigins)
`$env:PYTHONPATH = $(ConvertTo-PSLiteral ".;$BackendVendorDir")
if (-not `$env:WEKNORA_ADMIN_PASSWORD) { `$env:WEKNORA_ADMIN_PASSWORD = "1qaz@WSX" }
& $(ConvertTo-PSLiteral $BackendPython) -m uvicorn app.gateway.app:app --host $(ConvertTo-PSLiteral $BackendHost) --port $(ConvertTo-PSLiteral $BackendPort) --reload --reload-dir 'app' --reload-dir 'packages' --reload-exclude $(ConvertTo-PSLiteral (Join-Path $BackendDir '.deer-flow')) --reload-exclude $(ConvertTo-PSLiteral $RuntimeDir) *> $(ConvertTo-PSLiteral $LogFile)
"@
Set-Content -LiteralPath $RunnerFile -Value $runner -Encoding UTF8
$proc = Start-Process -FilePath "powershell.exe" -ArgumentList @(
"-NoProfile",
"-ExecutionPolicy", "Bypass",
"-File", $RunnerFile
) -WindowStyle Hidden -PassThru
Set-Content -LiteralPath $PidFile -Value $proc.Id
Write-Host "Backend started (pid $($proc.Id))."
Write-Host "URL: $BackendPublicBaseUrl"