From 0a74cb31d5cc7f3ea51c29db3db726b2816411b5 Mon Sep 17 00:00:00 2001 From: Daniel Hiltgen Date: Thu, 28 Mar 2024 14:26:17 -0700 Subject: [PATCH] Safeguard for noexec We may have users that run into problems with our current payload model, so this gives us an escape valve. --- docs/troubleshooting.md | 7 +++++++ gpu/assets.go | 15 ++++++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/docs/troubleshooting.md b/docs/troubleshooting.md index 7103be4d..b9038e38 100644 --- a/docs/troubleshooting.md +++ b/docs/troubleshooting.md @@ -76,3 +76,10 @@ install script which version to install. ```sh curl -fsSL https://ollama.com/install.sh | OLLAMA_VERSION="0.1.29" sh ``` + +## Linux tmp noexec + +If your system is configured with the "noexec" flag where Ollama stores its +temporary executable files, you can specify an alternate location by setting +OLLAMA_TMPDIR to a location writable by the user ollama runs as. For example +OLLAMA_TMPDIR=/usr/share/ollama/ \ No newline at end of file diff --git a/gpu/assets.go b/gpu/assets.go index 539635ee..085c05bc 100644 --- a/gpu/assets.go +++ b/gpu/assets.go @@ -22,11 +22,20 @@ var ( func PayloadsDir() (string, error) { lock.Lock() defer lock.Unlock() + var err error if payloadsDir == "" { cleanupTmpDirs() - tmpDir, err := os.MkdirTemp("", "ollama") - if err != nil { - return "", fmt.Errorf("failed to generate tmp dir: %w", err) + tmpDir := os.Getenv("OLLAMA_TMPDIR") + if tmpDir == "" { + tmpDir, err = os.MkdirTemp("", "ollama") + if err != nil { + return "", fmt.Errorf("failed to generate tmp dir: %w", err) + } + } else { + err = os.MkdirAll(tmpDir, 0755) + if err != nil { + return "", fmt.Errorf("failed to generate tmp dir %s: %w", tmpDir, err) + } } // Track our pid so we can clean up orphaned tmpdirs