This commit is contained in:
parent
6e3123091a
commit
aeddaa6972
69 changed files with 3178 additions and 424 deletions
|
|
@ -90,6 +90,30 @@ function Wait-Health([string]$url, [string]$label, [int]$timeoutSec = 40) {
|
|||
Write-Host " WARN $label 미응답 ($url) — .devlogs 로그 확인"; return $false
|
||||
}
|
||||
|
||||
function Wait-ApiDbHealth([string]$url, [int]$timeoutSec = 40) {
|
||||
$deadline = (Get-Date).AddSeconds($timeoutSec)
|
||||
while ((Get-Date) -lt $deadline) {
|
||||
try {
|
||||
$response = Invoke-WebRequest -Uri $url -TimeoutSec 4 -UseBasicParsing -ErrorAction Stop
|
||||
if ($response.StatusCode -eq 200) {
|
||||
$health = $response.Content | ConvertFrom-Json -ErrorAction Stop
|
||||
if ($health.db -is [bool] -and $health.db -eq $true) {
|
||||
Write-Host " OK api DB ($url)"
|
||||
return $true
|
||||
}
|
||||
}
|
||||
} catch { Start-Sleep -Milliseconds 600; continue }
|
||||
Start-Sleep -Milliseconds 600
|
||||
}
|
||||
Write-Host " WARN api DB 미준비 ($url) — .devlogs 로그 확인"
|
||||
return $false
|
||||
}
|
||||
|
||||
function Confirm-ManagedApiDbHealth([bool]$managedDbReady, [string]$url) {
|
||||
if (-not $managedDbReady) { return $true }
|
||||
return Wait-ApiDbHealth $url
|
||||
}
|
||||
|
||||
function Read-EnvFileValue([string]$path, [string]$key) {
|
||||
if (!(Test-Path -LiteralPath $path)) { return $null }
|
||||
$pattern = ('^\s*{0}\s*=' -f [regex]::Escape($key))
|
||||
|
|
@ -170,9 +194,9 @@ function Get-DevDbContainerEnvValue([string]$key, [string]$fallback) {
|
|||
return $fallback
|
||||
}
|
||||
|
||||
function Wait-DevDbReady([string]$ownerUser, [int]$attempts = 24) {
|
||||
function Wait-DevDbReady([string]$ownerUser, [string]$dbName, [int]$attempts = 24) {
|
||||
for ($i = 0; $i -lt $attempts; $i++) {
|
||||
Invoke-DockerProbe exec $DevDbContainerName pg_isready -U $ownerUser | Out-Null
|
||||
Invoke-DockerProbe exec $DevDbContainerName pg_isready -h 127.0.0.1 -p 5432 -U $ownerUser -d $dbName | Out-Null
|
||||
if ($LASTEXITCODE -eq 0) { return $true }
|
||||
Start-Sleep -Seconds 2
|
||||
}
|
||||
|
|
@ -186,12 +210,7 @@ function Inspect-DevDbContainer {
|
|||
}
|
||||
$ownerUser = Get-DevDbContainerEnvValue 'POSTGRES_USER' 'vignette_owner'
|
||||
$dbName = Get-DevDbContainerEnvValue 'POSTGRES_DB' 'vignette'
|
||||
Invoke-DockerProbe exec $DevDbContainerName pg_isready -U $ownerUser | Out-Null
|
||||
if ($LASTEXITCODE -eq 0) {
|
||||
Write-Host ' OK db (vignette-dev-db 준비됨)'
|
||||
} else {
|
||||
Write-Host ' WARN db 컨테이너는 있으나 pg_isready 실패'
|
||||
}
|
||||
Write-Host ' OK db (vignette-dev-db 준비됨)'
|
||||
Test-DevDbRoleSafety "$ownerUser" "$dbName"
|
||||
}
|
||||
|
||||
|
|
@ -205,7 +224,8 @@ function Start-ExistingDevDbContainer([string]$state) {
|
|||
throw '기존 vignette-dev-db 시작 실패. 데이터 교체 없이 중단함. pg_dump와 복구 검증을 갖춘 별도 유지보수 절차가 필요하다.'
|
||||
}
|
||||
$ownerUser = Get-DevDbContainerEnvValue 'POSTGRES_USER' 'vignette_owner'
|
||||
if (-not (Wait-DevDbReady $ownerUser)) {
|
||||
$dbName = Get-DevDbContainerEnvValue 'POSTGRES_DB' 'vignette'
|
||||
if (-not (Wait-DevDbReady $ownerUser $dbName)) {
|
||||
throw '기존 vignette-dev-db가 시작됐지만 pg_isready가 실패함. 컨테이너/볼륨을 교체하지 않고 중단함.'
|
||||
}
|
||||
Inspect-DevDbContainer
|
||||
|
|
@ -229,33 +249,38 @@ function Ensure-DevDbDataVolume {
|
|||
function Ensure-DevDb {
|
||||
if (!(Get-Command docker -ErrorAction SilentlyContinue)) {
|
||||
Write-Host ' WARN docker CLI 없음 - DB 없이 degraded(UI 세션 시작 제한).'
|
||||
return
|
||||
return $false
|
||||
}
|
||||
if (!(Test-Path -LiteralPath '\\.\pipe\dockerDesktopLinuxEngine')) {
|
||||
Write-Host ' WARN Docker Desktop Linux engine 미실행 - DB 없이 degraded(UI 세션 시작 제한).'
|
||||
return
|
||||
return $false
|
||||
}
|
||||
Invoke-DockerProbe ps | Out-Null
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
Write-Host ' WARN Docker 데몬 미응답 - DB 없이 degraded(UI 세션 시작 제한). Docker Desktop 실행 필요.'
|
||||
return
|
||||
return $false
|
||||
}
|
||||
|
||||
$containerState = Get-DevDbContainerState
|
||||
if (-not [string]::IsNullOrWhiteSpace($containerState)) {
|
||||
if ($containerState -eq 'running') {
|
||||
$ownerUser = Get-DevDbContainerEnvValue 'POSTGRES_USER' 'vignette_owner'
|
||||
$dbName = Get-DevDbContainerEnvValue 'POSTGRES_DB' 'vignette'
|
||||
if (-not (Wait-DevDbReady $ownerUser $dbName)) {
|
||||
throw '기존 실행 중 vignette-dev-db가 실제 TCP DB 준비 상태에 도달하지 못함. 컨테이너/볼륨을 교체하지 않고 중단함.'
|
||||
}
|
||||
Inspect-DevDbContainer
|
||||
return
|
||||
return $true
|
||||
}
|
||||
Start-ExistingDevDbContainer $containerState
|
||||
return
|
||||
return $true
|
||||
}
|
||||
|
||||
$apiEnv = Join-Path $api '.env'
|
||||
$dbUrl = Read-EnvFileValue $apiEnv 'DATABASE_URL'
|
||||
if ($dbUrl -notmatch 'postgresql://([^:]+):([^@]+)@[^:]+:([0-9]+)/(\S+)') {
|
||||
Write-Host ' WARN DATABASE_URL 파싱 실패 - DB 스킵'
|
||||
return
|
||||
return $false
|
||||
}
|
||||
|
||||
$u = $Matches[1]
|
||||
|
|
@ -293,11 +318,10 @@ function Ensure-DevDb {
|
|||
throw '새 vignette-dev-db 컨테이너 생성 실패. named PGDATA volume은 보존함.'
|
||||
}
|
||||
|
||||
if (Wait-DevDbReady $ownerUser) {
|
||||
if (Wait-DevDbReady $ownerUser $db) {
|
||||
Write-Host ' OK db (Postgres 준비됨, named PGDATA + init 스키마 적용)'
|
||||
Test-DevDbRoleSafety $ownerUser $db
|
||||
Start-Sleep -Seconds 1
|
||||
return
|
||||
return $true
|
||||
}
|
||||
throw '새 vignette-dev-db 준비 타임아웃. 컨테이너와 named PGDATA volume은 조사/복구를 위해 보존함.'
|
||||
}
|
||||
|
|
@ -315,10 +339,11 @@ if (-not $NoWeb) {
|
|||
}
|
||||
Start-Sleep -Seconds 2
|
||||
|
||||
$managedDbReady = $false
|
||||
if (-not $NoDb) {
|
||||
Write-Host '[DB] Postgres(pgvector) 보장...'
|
||||
Warn-ComposeEnvReadiness
|
||||
Ensure-DevDb
|
||||
$managedDbReady = Ensure-DevDb
|
||||
}
|
||||
|
||||
if ($UseHiggsVoice) {
|
||||
|
|
@ -358,7 +383,14 @@ Write-Host '헬스 체크:'
|
|||
if (-not $NoGateway) {
|
||||
Wait-Health 'http://127.0.0.1:9099/health' 'gateway' | Out-Null
|
||||
}
|
||||
Wait-Health "http://127.0.0.1:$ApiPort/health" 'api' | Out-Null
|
||||
if ($managedDbReady) {
|
||||
if (-not (Confirm-ManagedApiDbHealth $managedDbReady "http://127.0.0.1:$ApiPort/health")) {
|
||||
Write-Host 'ERROR: 관리 DB는 준비됐지만 API health의 db=true를 확인하지 못함. API를 자동 재시작하지 않고 중단함.'
|
||||
exit 1
|
||||
}
|
||||
} else {
|
||||
Wait-Health "http://127.0.0.1:$ApiPort/health" 'api' | Out-Null
|
||||
}
|
||||
if (-not $NoWeb) {
|
||||
Wait-Health 'http://localhost:5173/' 'web' | Out-Null
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue