43 lines
1.7 KiB
PowerShell
43 lines
1.7 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" }
|
|
cmd.exe /c "`"$(($BackendPython -replace '"', '\"'))`" -m uvicorn app.gateway.app:app --host $(($BackendHost -replace '"', '\"')) --port $(($BackendPort -replace '"', '\"')) --reload > `"$(($LogFile -replace '"', '\"'))`" 2>&1"
|
|
"@
|
|
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"
|