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
160d9d49
Unverified
Commit
160d9d49
authored
Aug 09, 2024
by
Michael Yang
Committed by
GitHub
Aug 09, 2024
Browse files
Merge pull request #6171 from ollama/mxyng/remove-temp
removeall to remove non-empty temp dirs
parents
b7f7d8cd
43f9d920
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
23 deletions
+26
-23
gpu/assets.go
gpu/assets.go
+26
-23
No files found.
gpu/assets.go
View file @
160d9d49
...
@@ -49,13 +49,9 @@ func PayloadsDir() (string, error) {
...
@@ -49,13 +49,9 @@ func PayloadsDir() (string, error) {
}
}
// Track our pid so we can clean up orphaned tmpdirs
// Track our pid so we can clean up orphaned tmpdirs
pidFilePath
:=
filepath
.
Join
(
tmpDir
,
"ollama.pid"
)
n
:=
filepath
.
Join
(
tmpDir
,
"ollama.pid"
)
pidFile
,
err
:=
os
.
OpenFile
(
pidFilePath
,
os
.
O_CREATE
|
os
.
O_TRUNC
|
os
.
O_WRONLY
,
os
.
ModePerm
)
if
err
:=
os
.
WriteFile
(
n
,
[]
byte
(
strconv
.
Itoa
(
os
.
Getpid
())),
0
o644
);
err
!=
nil
{
if
err
!=
nil
{
return
""
,
fmt
.
Errorf
(
"failed to write pid file %s: %w"
,
n
,
err
)
return
""
,
err
}
if
_
,
err
:=
pidFile
.
Write
([]
byte
(
strconv
.
Itoa
(
os
.
Getpid
())));
err
!=
nil
{
return
""
,
err
}
}
// We create a distinct subdirectory for payloads within the tmpdir
// We create a distinct subdirectory for payloads within the tmpdir
...
@@ -67,37 +63,44 @@ func PayloadsDir() (string, error) {
...
@@ -67,37 +63,44 @@ func PayloadsDir() (string, error) {
// Best effort to clean up prior tmpdirs
// Best effort to clean up prior tmpdirs
func
cleanupTmpDirs
()
{
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
{
if
err
!=
nil
{
return
return
}
}
for
_
,
d
:=
range
dirs
{
info
,
err
:=
os
.
Stat
(
d
)
for
_
,
match
:=
range
matches
{
if
err
!=
nil
||
!
info
.
IsDir
()
{
raw
,
err
:=
os
.
ReadFile
(
match
)
if
errors
.
Is
(
err
,
os
.
ErrNotExist
)
{
slog
.
Debug
(
"not a ollama runtime directory, skipping"
,
"path"
,
match
)
continue
continue
}
}
else
if
err
!=
nil
{
raw
,
err
:=
os
.
ReadFile
(
filepath
.
Join
(
d
,
"ollama.pid"
))
slog
.
Warn
(
"could not read ollama.pid, skipping"
,
"path"
,
match
,
"error"
,
err
)
if
err
!=
nil
{
slog
.
Warn
(
"failed to read ollama.pid"
,
"path"
,
d
,
"error"
,
err
)
// No pid, ignore this tmpdir
continue
continue
}
}
pid
,
err
:=
strconv
.
Atoi
(
string
(
raw
))
pid
,
err
:=
strconv
.
Atoi
(
string
(
raw
))
if
err
!=
nil
{
if
err
!=
nil
{
slog
.
Warn
(
"
failed to parse pid
"
,
"path"
,
d
,
"error"
,
err
)
slog
.
Warn
(
"
invalid pid, skipping
"
,
"path"
,
match
,
"error"
,
err
)
continue
continue
}
}
proc
,
err
:=
os
.
FindProcess
(
pid
)
p
,
err
:=
os
.
FindProcess
(
pid
)
if
err
==
nil
&&
!
errors
.
Is
(
proc
.
Signal
(
syscall
.
Signal
(
0
)),
os
.
ErrProcessDone
)
{
if
err
==
nil
&&
!
errors
.
Is
(
p
.
Signal
(
syscall
.
Signal
(
0
)),
os
.
ErrProcessDone
)
{
slog
.
Warn
(
"found running ollama"
,
"pid"
,
pid
,
"path"
,
d
)
slog
.
Warn
(
"process still running, skipping"
,
"pid"
,
pid
,
"path"
,
match
)
// Another running ollama, ignore this tmpdir
continue
continue
}
}
if
err
:=
os
.
Remove
(
d
);
err
!=
nil
{
if
err
:=
os
.
Remove
(
match
);
err
!=
nil
{
slog
.
Warn
(
"unable to cleanup stale tmpdir"
,
"path"
,
d
,
"error"
,
err
)
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