diff --git a/jj_ollama_manager.ps1 b/jj_ollama_manager.ps1 index 38f7852..403b2c9 100644 --- a/jj_ollama_manager.ps1 +++ b/jj_ollama_manager.ps1 @@ -188,6 +188,8 @@ $script:Installed = @() $script:LaunchDone = $false $script:PodmanExe = $null $script:PodmanVer = $null +$script:LanIp = '' # Get-LanIp 가 기억해 둔 내부망 IP +$script:LanIpKnown = $false $script:KeyHelp = "${GRAY}↑↓ 이동 · Enter/→ 선택 · ←/Esc 이전 메뉴 · 글자 입력 시 검색${RESET}" $script:MainKeyHelp = "${GRAY}↑↓ 이동 · Enter/→ 선택 · Esc 종료 · 글자 입력 시 검색${RESET}" @@ -1635,6 +1637,7 @@ function Stop-OllamaServer { # 서버 재시작 function Restart-OllamaServer([int]$Ctx = 0) { if ($Ctx -le 0) { $Ctx = $script:Perf.ContextLength } + $script:LanIpKnown = $false # 내부망 IP 새로 알아내기 if (Test-Server) { if (-not (Confirm-NoActiveClients '재시작')) { return $false } } @@ -2722,12 +2725,17 @@ function Test-Wsl { } # 이 PC의 내부망 IP 주소 -function Get-LanIp { +# Get-NetIPAddress 가 1초 넘게 걸려서 한 번 알아낸 값을 기억해 둠 +# (서버 재시작 · WebUI 기동 때, 또는 -Refresh 로 새로 알아냄) +function Get-LanIp([switch]$Refresh) { + if (-not $Refresh -and $script:LanIpKnown) { return $script:LanIp } $ip = Get-NetIPAddress -AddressFamily IPv4 -ErrorAction SilentlyContinue | Where-Object { $_.IPAddress -notmatch '^(127\.|169\.254\.)' -and $_.InterfaceAlias -notmatch 'vEthernet|WSL|Loopback|Hyper-V' } | Sort-Object InterfaceMetric | Select-Object -First 1 - if ($ip) { return $ip.IPAddress } - return '' + $script:LanIp = '' + if ($ip) { $script:LanIp = $ip.IPAddress } + $script:LanIpKnown = $true + return $script:LanIp } # Windows 경로 → Podman 가상 머신(WSL) 안의 경로 (M:\webui\data → /mnt/m/webui/data) @@ -2880,10 +2888,21 @@ if getent hosts registry-1.docker.io >/dev/null 2>&1; then echo DNS_FIXED; else # 컨테이너 상태 (State: none/running/exited/paused/created..., Status: 한글 상태 문구) function Get-WebuiInfo { $info = [pscustomobject]@{ State = 'none'; Status = '' } - $st = & $script:PodmanExe container inspect $WebuiName --format '{{.State.Status}}' 2>$null - if ($LASTEXITCODE -ne 0 -or -not "$st".Trim()) { return $info } - $info.State = "$st".Trim() - $s = "$(& $script:PodmanExe ps -a --filter "name=^${WebuiName}`$" --format '{{.Status}}' 2>$null | Select-Object -First 1)" + # 상태(running/exited…)와 설명(Up 5 minutes…)을 podman 명령 한 번으로 받음 + $out = @(& $script:PodmanExe ps -a --filter "name=^${WebuiName}`$" --format '{{.State}}|{{.Status}}' 2>$null) + $ok = ($LASTEXITCODE -eq 0) + $line = "$($out | Select-Object -First 1)" + $parts = $line -split '\|', 2 + $st = $parts[0].Trim() + $s = '' + if ($parts.Count -gt 1) { $s = $parts[1] } + if (-not $ok -or ($line.Trim() -and -not $st)) { + # 명령이 실패했거나 이 Podman 에서 {{.State}} 를 못 쓰면 예전 방식 (명령 2번) + $st = "$(& $script:PodmanExe container inspect $WebuiName --format '{{.State.Status}}' 2>$null)".Trim() + $s = "$(& $script:PodmanExe ps -a --filter "name=^${WebuiName}`$" --format '{{.Status}}' 2>$null | Select-Object -First 1)" + } + if (-not $st) { return $info } + $info.State = $st.ToLower() $s = $s -replace '^Up ', '가동 ' -replace '^Exited \((\d+)\) ', '종료(코드 $1) ' -replace '^Created', '생성됨' $s = $s -replace 'About a minute', '1분' -replace 'About an hour', '1시간' -replace 'Less than a second', '1초 미만' $s = $s -replace ' seconds?', '초' -replace ' minutes?', '분' -replace ' hours?', '시간' -replace ' days?', '일' -replace ' weeks?', '주' -replace ' months?', '개월' @@ -3035,6 +3054,7 @@ function Test-OllamaReachableForWebui { # WebUI 기동 function Start-Webui { + $script:LanIpKnown = $false # 내부망 IP 새로 알아내기 if (-not (Confirm-Podman)) { return } if (-not (Confirm-PodmanMachine)) { return } Test-OllamaReachableForWebui