Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
ollama
Commits
ed6c8bfe
Commit
ed6c8bfe
authored
Aug 05, 2024
by
Michael Yang
Browse files
removeall to remove non-empty temp dirs
parent
8b920f35
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
16 deletions
+23
-16
gpu/assets.go
gpu/assets.go
+23
-16
No files found.
gpu/assets.go
View file @
ed6c8bfe
...
...
@@ -67,37 +67,44 @@ func PayloadsDir() (string, error) {
// Best effort to clean up prior tmpdirs
func
cleanupTmpDirs
()
{
dir
s
,
err
:=
filepath
.
Glob
(
filepath
.
Join
(
os
.
TempDir
(),
"ollama*"
))
matche
s
,
err
:=
filepath
.
Glob
(
filepath
.
Join
(
os
.
TempDir
(),
"ollama*"
,
"ollama.pid"
))
if
err
!=
nil
{
return
}
for
_
,
d
:=
range
dirs
{
info
,
err
:=
os
.
Stat
(
d
)
if
err
!=
nil
||
!
info
.
IsDir
()
{
for
_
,
match
:=
range
matches
{
raw
,
err
:=
os
.
ReadFile
(
match
)
if
errors
.
Is
(
err
,
os
.
ErrNotExist
)
{
slog
.
Debug
(
"not a ollama runtime directory, skipping"
,
"path"
,
match
)
continue
}
raw
,
err
:=
os
.
ReadFile
(
filepath
.
Join
(
d
,
"ollama.pid"
))
if
err
!=
nil
{
slog
.
Warn
(
"failed to read ollama.pid"
,
"path"
,
d
,
"error"
,
err
)
// No pid, ignore this tmpdir
}
else
if
err
!=
nil
{
slog
.
Warn
(
"could not read ollama.pid, skipping"
,
"path"
,
match
,
"error"
,
err
)
continue
}
pid
,
err
:=
strconv
.
Atoi
(
string
(
raw
))
if
err
!=
nil
{
slog
.
Warn
(
"
failed to parse pid
"
,
"path"
,
d
,
"error"
,
err
)
slog
.
Warn
(
"
invalid pid, skipping
"
,
"path"
,
match
,
"error"
,
err
)
continue
}
proc
,
err
:=
os
.
FindProcess
(
pid
)
if
err
==
nil
&&
!
errors
.
Is
(
proc
.
Signal
(
syscall
.
Signal
(
0
)),
os
.
ErrProcessDone
)
{
slog
.
Warn
(
"found running ollama"
,
"pid"
,
pid
,
"path"
,
d
)
// Another running ollama, ignore this tmpdir
p
,
err
:=
os
.
FindProcess
(
pid
)
if
err
==
nil
&&
!
errors
.
Is
(
p
.
Signal
(
syscall
.
Signal
(
0
)),
os
.
ErrProcessDone
)
{
slog
.
Warn
(
"process still running, skipping"
,
"pid"
,
pid
,
"path"
,
match
)
continue
}
if
err
:=
os
.
Remove
(
d
);
err
!=
nil
{
slog
.
Warn
(
"unable to cleanup stale tmpdir"
,
"path"
,
d
,
"error"
,
err
)
if
err
:=
os
.
Remove
(
match
);
err
!=
nil
{
slog
.
Warn
(
"could not cleanup stale pidfile"
,
"path"
,
match
,
"error"
,
err
)
}
runners
:=
filepath
.
Join
(
filepath
.
Dir
(
match
),
"runners"
)
if
err
:=
os
.
RemoveAll
(
runners
);
err
!=
nil
{
slog
.
Warn
(
"could not cleanup stale runners"
,
"path"
,
runners
,
"error"
,
err
)
}
if
err
:=
os
.
Remove
(
filepath
.
Dir
(
match
));
err
!=
nil
{
slog
.
Warn
(
"could not cleanup stale tmpdir"
,
"path"
,
filepath
.
Dir
(
match
),
"error"
,
err
)
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment