Files
JJOllamaManager/src/platform/windows/14_storage_quickopen.ps1
diadmin f567af2dc4 Ollama 서버 재시작: 모델 저장 위치 유지·변경·이동 (Windows·Mac)
- 재시작 메뉴: 그대로(기본) / 저장 위치 바꾸고 기존 모델 옮겨서 / 저장 위치만 바꿔서(기존 모델 그대로)
- ollama_models_change nomove, Set-OllamaModelsLocation -NoMove 추가 ('모델 저장 위치' 메뉴는 그대로)
- 서버가 꺼져 있었으면 바꾼 위치로 기동, 위치를 바꾸지 않으면 재시작하지 않음
- (Windows 19_ollama_restart.ps1, Mac 19_ollama_restart.sh)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HnDmXrFqktWwYa1cuJRAVZ
2026-11-05 05:47:43 +00:00

286 lines
17 KiB
PowerShell
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# JJ Ollama Manager (Windows) — src/platform/windows/14_storage_quickopen.ps1 : 999 웹 화면 바로 열기 (어느 메뉴에서나)
# jj_ollama_manager.ps1 가 순서대로 불러옵니다 (직접 실행하지 않음). 원래 jj_ollama_manager.ps1 5066~5337줄
# 새 폴더 고르기: 폴더 선택 창 또는 직접 입력 → 전체 경로 / $null
function Select-FolderPath([string]$Title, [string]$Current, [string]$Default) {
$items = @(
(New-MenuItem 'dialog' " 폴더 선택 창 열기")
(New-MenuItem 'type' " 경로 직접 입력 ${GRAY}(예: D:\AI\models)${RESET}")
)
if ($Current -ne $Default) { $items += New-MenuItem 'default' " 기본 위치로 되돌리기 ${GRAY}($Default)${RESET}" }
$items += Get-BackItem '← 취소'
$sel = Show-Menu -Header "${BLUE}$Title${RESET}`n${GRAY}현재: $Current${RESET}`n$($script:KeyHelp)" -Items $items
$path = $null
switch ($sel) {
'dialog' {
try {
Add-Type -AssemblyName System.Windows.Forms -ErrorAction Stop
$owner = New-Object System.Windows.Forms.Form -Property @{ TopMost = $true }
$dlg = New-Object System.Windows.Forms.FolderBrowserDialog
$dlg.Description = $Title
$dlg.ShowNewFolderButton = $true
if (Test-Path -LiteralPath $Current) { $dlg.SelectedPath = $Current }
if ($dlg.ShowDialog($owner) -eq [System.Windows.Forms.DialogResult]::OK) { $path = $dlg.SelectedPath }
$owner.Dispose()
} catch {
Write-C "${YELLOW}폴더 선택 창을 열지 못했습니다. 경로를 직접 입력해 주세요.${RESET}"
$path = (Read-Host '새 폴더 경로 (엔터만 누르면 취소)').Trim().Trim('"')
}
}
'type' { $path = (Read-Host '새 폴더 경로 (엔터만 누르면 취소)').Trim().Trim('"') }
'default' { $path = $Default }
}
if (-not $path) { return $null }
try { $path = [IO.Path]::GetFullPath($path).TrimEnd('\') } catch { Write-C "${RED}올바른 경로가 아닙니다: $path${RESET}"; return $null }
if ($path -notmatch '^[A-Za-z]:\\.+') {
Write-C "${RED}드라이브 문자로 시작하는 폴더를 지정해 주세요. (예: D:\AI\models, 드라이브 맨 위는 불가)${RESET}"
return $null
}
return $path
}
# 두 경로가 같거나 한쪽이 다른 쪽 안에 있는지
function Test-PathOverlap([string]$A, [string]$B) {
$a = $A.TrimEnd('\').ToLower() + '\'
$b = $B.TrimEnd('\').ToLower() + '\'
return ($a.StartsWith($b) -or $b.StartsWith($a))
}
# 폴더 안의 내용을 새 폴더로 옮김 (같은 드라이브·빈 폴더면 순간 이동, 아니면 robocopy로 복사 후 삭제)
function Move-FolderContent([string]$Src, [string]$Dst) {
if (-not (Test-Path -LiteralPath $Dst)) { New-Item -ItemType Directory -Path $Dst -Force | Out-Null }
if (-not (Test-Path -LiteralPath $Src)) { return $true }
$children = @(Get-ChildItem -LiteralPath $Src -Force -ErrorAction SilentlyContinue)
if ($children.Count -eq 0) { return $true }
$sameDrive = ((Split-Path -Qualifier $Src) -eq (Split-Path -Qualifier $Dst))
$dstEmpty = (@(Get-ChildItem -LiteralPath $Dst -Force -ErrorAction SilentlyContinue).Count -eq 0)
if ($sameDrive -and $dstEmpty) {
try {
foreach ($c in $children) { Move-Item -LiteralPath $c.FullName -Destination $Dst -Force -ErrorAction Stop }
return $true
} catch {
Write-C "${YELLOW}바로 옮기지 못해 복사 방식으로 진행합니다: $($_.Exception.Message)${RESET}"
}
}
Write-C "${CYAN}옮기는 중... (다른 드라이브면 크기에 따라 시간이 걸립니다)${RESET}"
& robocopy.exe $Src $Dst /E /MOVE /R:1 /W:1 /NFL /NDL /NJH /NP | Out-Host
$rc = $LASTEXITCODE
if ($rc -ge 8) { Write-C "${RED}❌ 옮기는 중 오류가 났습니다 (robocopy 코드 $rc). 원래 폴더의 남은 파일을 확인해 주세요: $Src${RESET}"; return $false }
return $true
}
# 공통 확인: 겹침·남은 공간
function Test-MoveTarget([string]$Old, [string]$New, [double]$SizeGB) {
if ($Old.TrimEnd('\') -eq $New.TrimEnd('\')) { Write-C "${YELLOW}지금과 같은 위치입니다.${RESET}"; return $false }
if (Test-PathOverlap $Old $New) { Write-C "${RED}❌ 지금 폴더 안이나 바깥 폴더로는 옮길 수 없습니다. 다른 폴더를 골라 주세요.${RESET}"; return $false }
$sameDrive = ((Split-Path -Qualifier $Old) -eq (Split-Path -Qualifier $New))
$free = Get-PathFreeGB $New
if ($free -lt 0) { Write-C "${RED}❌ 드라이브를 찾을 수 없습니다: $New${RESET}"; return $false }
if (-not $sameDrive -and $free -lt ($SizeGB + 1)) {
Write-C "${RED}❌ 남은 공간이 부족합니다. 필요 약 $([math]::Ceiling($SizeGB + 1))GB · 남은 공간 ${free}GB${RESET}"
return $false
}
return $true
}
# Ollama 모델 저장 위치 변경
# -NoMove: 위치만 바꾸고 기존 모델은 지금 위치에 그대로 둠
function Set-OllamaModelsLocation([switch]$NoMove) {
$old = Get-ModelsDir
$new = Select-FolderPath 'Ollama 모델 저장 위치 변경' $old $OllamaModelsDefault
if (-not $new) { return }
Clear-Host
$size = Get-PathSizeGB $old
if ($NoMove) {
if ($old.TrimEnd('\') -eq $new.TrimEnd('\')) { Write-C "${YELLOW}지금과 같은 위치입니다.${RESET}"; return }
if (-not (Test-Path -LiteralPath $new)) { New-Item -ItemType Directory -Path $new -Force -ErrorAction SilentlyContinue | Out-Null }
if (-not (Test-Path -LiteralPath $new)) { Write-C "${RED}❌ 폴더를 만들 수 없습니다: $new${RESET}"; return }
Write-C "${CYAN}Ollama 모델 저장 위치를 바꿉니다 (기존 모델은 옮기지 않음)${RESET}"
} else {
if (-not (Test-MoveTarget $old $new $size)) { return }
Write-C "${CYAN}Ollama 모델 저장 위치를 바꿉니다${RESET}"
}
Write-C " 지금: $old ($size GB)"
Write-C " 새 위치: $new (남은 공간 $(Get-PathFreeGB $new)GB)"
if ($NoMove) { Write-C "${GRAY} 받은 모델은 지금 위치($old)에 그대로 두고, 사용자 환경 변수 OLLAMA_MODELS 만 새 위치로 바꿉니다. (새 위치에 모델이 없으면 목록이 비어 보임)${RESET}" }
else { Write-C "${GRAY} 받은 모델은 새 위치로 옮기고, 사용자 환경 변수 OLLAMA_MODELS 에 저장합니다.${RESET}" }
$wasRunning = Test-Server
$owner = ''
if ($wasRunning) {
$owner = (Get-ServerInfo).Owner
Write-C "${YELLOW} 옮기는 동안 Ollama 서버를 잠시 종료합니다.${RESET}"
}
$q = if ($NoMove) { '저장 위치를 새 위치로 바꿀까요? (모델은 옮기지 않음)' } else { 'Ollama 모델을 새 위치로 옮길까요?' }
if (-not (Confirm-Choice $q)) { return }
$before = @((Get-ModelIdMap).Keys).Count
if ($wasRunning) {
Stop-OllamaServer
if (Test-Server) { Write-C "${RED}❌ 서버가 아직 실행 중이라 옮기지 않았습니다.${RESET}"; return }
}
if (-not $NoMove) { if (-not (Move-FolderContent $old $new)) { return } }
if ($new -eq $OllamaModelsDefault) {
[Environment]::SetEnvironmentVariable('OLLAMA_MODELS', $null, 'User')
Remove-Item Env:OLLAMA_MODELS -ErrorAction SilentlyContinue
} else {
[Environment]::SetEnvironmentVariable('OLLAMA_MODELS', $new, 'User')
$env:OLLAMA_MODELS = $new
}
if ((-not $NoMove) -and (Test-Path -LiteralPath $old) -and @(Get-ChildItem -LiteralPath $old -Recurse -File -Force -ErrorAction SilentlyContinue).Count -eq 0) {
Remove-Item -LiteralPath $old -Recurse -Force -ErrorAction SilentlyContinue
}
Clear-StorageCache
Write-C "${GREEN}✅ 저장 위치를 바꿨습니다: $new${RESET}"
if ($wasRunning) {
Write-C "${CYAN}서버를 다시 기동합니다...${RESET}"
[void](Invoke-ServerLaunch $script:Perf.ContextLength)
Start-Sleep -Seconds 1
$after = @((Get-ModelIdMap).Keys).Count
if ($NoMove) { Write-C "${GREEN}✅ 새 위치에서 모델 ${after}개가 보입니다. (기존 모델 ${before}개는 $old 에 그대로 있음)${RESET}" }
elseif ($after -eq $before) { Write-C "${GREEN}✅ 실행 확인: 설치된 모델 ${after}개가 새 위치에서 그대로 보입니다.${RESET}" }
else { Write-C "${YELLOW}⚠️ 모델 개수가 다릅니다 (전 ${before}개 → 지금 ${after}개). 새 폴더를 확인해 주세요: $new${RESET}" }
}
if ($owner -and $owner -ne '스크립트') {
Write-C "${YELLOW}※ 서버를 Ollama 트레이 앱이 켜고 있었습니다. 트레이 아이콘에서 Quit 후 다시 실행해야 앱도 새 위치를 씁니다.${RESET}"
}
}
# ComfyUI 모델 저장 위치 변경 (모든 버전 공용)
function Set-ComfyModelsLocation {
$old = $ComfyModels
$default = Join-Path $ComfyDir 'models'
$new = Select-FolderPath 'ComfyUI 그림 모델 저장 위치 변경 (모든 버전 공용)' $old $default
if (-not $new) { return }
Clear-Host
# 네트워크 드라이브는 Podman 가상 머신(WSL)에서 보이지 않음
try {
$drv = Get-PSDrive -Name ((Split-Path -Qualifier $new).TrimEnd(':')) -ErrorAction Stop
if ("$($drv.DisplayRoot)" -like '\\*') {
Write-C "${RED}❌ 네트워크 드라이브($($drv.Name): → $($drv.DisplayRoot))는 ComfyUI 컨테이너에서 쓸 수 없습니다. 이 PC의 디스크를 골라 주세요.${RESET}"
return
}
} catch { }
$size = Get-PathSizeGB $old
if (-not (Test-MoveTarget $old $new $size)) { return }
Write-C "${CYAN}ComfyUI 그림 모델 저장 위치를 바꿉니다${RESET}"
Write-C " 지금: $old ($size GB)"
Write-C " 새 위치: $new (남은 공간 $(Get-PathFreeGB $new)GB)"
Write-C "${GRAY} 받은 모델을 옮긴 뒤, ComfyUI 컨테이너를 새 위치로 다시 만듭니다. (작업흐름·그림은 그대로)${RESET}"
$list = @(Get-ComfyInstances)
$running = @()
if ($list.Count -gt 0 -and (Test-Podman) -and (Get-MachineInfo).State -eq 'running') {
$states = Get-ComfyStates
$running = @($list | Where-Object { $states[$_.Container] -eq 'running' })
if ($running.Count -gt 0) { Write-C "${YELLOW} 실행 중인 ComfyUI($(@($running | ForEach-Object { $_.Name }) -join ', '))는 잠시 종료했다가 다시 켭니다.${RESET}" }
}
if (-not (Confirm-Choice "ComfyUI 모델을 새 위치로 옮길까요?")) { return }
foreach ($i in $running) { Stop-ComfyInstance $i }
if (-not (Move-FolderContent $old $new)) { return }
if (-not (Test-Path $CacheDir)) { New-Item -ItemType Directory -Path $CacheDir -Force | Out-Null }
if ($new -eq $default) { Remove-Item $ComfyModelsFile -Force -ErrorAction SilentlyContinue }
else { [IO.File]::WriteAllText($ComfyModelsFile, $new, $Utf8NoBom) }
$script:ComfyModels = $new
if ((Test-Path -LiteralPath $old) -and @(Get-ChildItem -LiteralPath $old -Recurse -File -Force -ErrorAction SilentlyContinue).Count -eq 0 -and $old -ne $default) {
Remove-Item -LiteralPath $old -Recurse -Force -ErrorAction SilentlyContinue
}
Clear-StorageCache
Write-C "${GREEN}✅ 저장 위치를 바꿨습니다: $new${RESET}"
# 컨테이너는 만들 때 폴더를 연결하므로 다시 만들어야 새 위치를 씀
if ($list.Count -gt 0 -and (Test-Podman) -and (Get-MachineInfo).State -eq 'running') {
foreach ($i in $list) { & $script:PodmanExe rm -f $i.Container *> $null }
Write-C "${GRAY}ComfyUI 컨테이너를 정리했습니다. 다음 기동 때 새 위치로 다시 만들어집니다.${RESET}"
foreach ($i in $running) { [void](Start-ComfyInstance $i) }
}
}
function Show-StorageMenu {
while ($true) {
Clear-StorageCache
$s = Get-StorageInfo
$items = @(
(New-MenuItem '-' "${CYAN}──────── Ollama 대화 모델 ────────${RESET}" '-o')
(New-MenuItem 'o_change' " 저장 위치 변경 ${GRAY}$($s.OllamaDir) · $($s.OllamaGB)GB · 남은 $($s.OllamaFree)GB${RESET}")
(New-MenuItem 'o_open' ' 폴더 열기')
(New-MenuItem '-' "${CYAN}──────── ComfyUI 그림 모델 (모든 버전 공용) ────────${RESET}" '-c')
(New-MenuItem 'c_change' " 저장 위치 변경 ${GRAY}$($s.ComfyDir) · $($s.ComfyGB)GB · 남은 $($s.ComfyFree)GB${RESET}")
(New-MenuItem 'c_open' ' 폴더 열기')
(Get-BackItem)
)
$sel = Show-Menu -Header "${BLUE}${BOLD}모델 저장 위치${RESET} ${GRAY}위치를 바꾸면 받은 모델은 새 위치로 옮깁니다${RESET}`n$($script:KeyHelp)" -Items $items
if (-not $sel -or $sel -eq 'back') { return }
if ($sel -eq '-') { continue }
switch ($sel) {
'o_change' { Set-OllamaModelsLocation; Wait-Return }
'c_change' { Set-ComfyModelsLocation; Wait-Return }
'o_open' { $d = Get-ModelsDir; if (-not (Test-Path -LiteralPath $d)) { New-Item -ItemType Directory -Path $d -Force | Out-Null }; Invoke-Item -LiteralPath $d }
'c_open' { if (-not (Test-Path -LiteralPath $ComfyModels)) { New-Item -ItemType Directory -Path $ComfyModels -Force | Out-Null }; Invoke-Item -LiteralPath $ComfyModels }
}
}
}
# --------------------------------------------------
# 999 웹 화면 바로 열기 (어느 메뉴에서나)
# --------------------------------------------------
function Invoke-QuickOpen {
$script:InQuickOpen = $true
try {
while ($true) {
$podOn = (Test-Podman) -and ((Get-MachineInfo -Cached).State -eq 'running')
$items = @()
$items += New-MenuItem '-' "${CYAN}──────── Open WebUI (대화) ────────${RESET}" '-q1'
$wst = "${GRAY}[꺼짐 → 켠 뒤 열기]${RESET}"
if (Test-WebuiHealth) { $wst = "${GREEN}[실행 중]${RESET}" }
$items += New-MenuItem 'webui' " Open WebUI http://localhost:$WebuiPort $wst"
$items += New-MenuItem '-' "${CYAN}──────── ComfyUI (그림 생성) ────────${RESET}" '-q2'
$list = @(Get-ComfyInstances)
if ($list.Count -eq 0) {
$items += New-MenuItem 'c_install' " + ComfyUI 설치 후 열기 ${GRAY}(최신 안정판, 처음에는 5~15분)${RESET}"
} else {
$states = @{}
if ($podOn) { $states = Get-ComfyStates }
foreach ($i in $list) {
$cst = "${GRAY}[꺼짐 → 켠 뒤 열기]${RESET}"
if ($states[$i.Container] -eq 'running') { $cst = "${GREEN}[실행 중]${RESET}" }
$items += New-MenuItem "c:$($i.Name)" " ComfyUI $($i.Name) http://localhost:$($i.Port) $cst"
}
}
$items += Get-BackItem '← 원래 메뉴로 돌아가기'
$sel = Show-Menu -Header "${BLUE}${BOLD}999 · 웹 화면 바로 열기${RESET} ${GRAY}고르면 브라우저로 엽니다 (꺼져 있으면 먼저 켭니다)${RESET}`n$($script:KeyHelp)" -Items $items -NoQuick
if (-not $sel -or $sel -eq 'back') { return }
if ($sel -eq '-') { continue }
Clear-Host
if ($sel -eq 'webui') {
if (-not (Test-WebuiHealth)) {
Write-C "${CYAN}Open WebUI가 꺼져 있어 먼저 켭니다...${RESET}"
Start-Webui
}
if (Test-WebuiHealth) {
Start-Process "http://localhost:$WebuiPort"
Write-C "${GREEN}`n✅ 브라우저로 열었습니다: http://localhost:$WebuiPort${RESET}"
Show-WebuiUrls
} else {
Write-C "${RED}❌ Open WebUI가 응답하지 않아 열지 못했습니다.${RESET}"
}
} elseif ($sel -eq 'c_install' -or $sel -like 'c:*') {
if ($sel -eq 'c_install') { $inst = Install-ComfyQuick } else { $inst = Find-ComfyInstance ($sel.Substring(2)) }
if ($inst) {
if (-not (Get-ComfyStats $inst.Port 2)) {
Write-C "${CYAN}ComfyUI $($inst.Name)이 꺼져 있어 먼저 켭니다...${RESET}"
[void](Start-ComfyInstance $inst)
}
if (Get-ComfyStats $inst.Port 2) {
Start-Process "http://localhost:$($inst.Port)"
Write-C "${GREEN}`n✅ 브라우저로 열었습니다: http://localhost:$($inst.Port)${RESET}"
Show-ComfyUrls $inst
} else {
Write-C "${RED}❌ ComfyUI $($inst.Name)이 응답하지 않아 열지 못했습니다.${RESET}"
}
}
}
Wait-Return
return
}
} finally {
$script:InQuickOpen = $false
}
}