seriffic commited on
Commit
bebe2d4
·
1 Parent(s): b609855

entrypoint: write ollama log to $HOME (HF Spaces locks /tmp)

Browse files

HF Spaces mounts a read-only or quota-restricted /tmp; ollama serve
> /tmp/ollama.log fails on container start with EACCES. Move the log
to $HOME/.ollama-server.log and pull the model proactively if it's
not already in the cache, so the first user request doesn't pay the
load latency.

Files changed (1) hide show
  1. entrypoint.sh +27 -9
entrypoint.sh CHANGED
@@ -1,24 +1,42 @@
1
  #!/usr/bin/env sh
2
  # Start Ollama daemon in the background, wait for it to be ready,
3
  # then launch uvicorn on the HF Spaces default port.
 
 
 
4
  set -e
5
 
6
- ollama serve > /tmp/ollama.log 2>&1 &
 
7
  OLLAMA_PID=$!
8
 
9
- # Wait for Ollama to be reachable (up to 30 s)
10
- for i in $(seq 1 30); do
 
11
  if curl -sf http://127.0.0.1:11434/ > /dev/null 2>&1; then
12
- echo "[entrypoint] ollama up (pid $OLLAMA_PID)"
13
  break
14
  fi
 
 
 
 
 
15
  sleep 1
16
  done
17
 
18
- # Sanity check: Granite 4.1 model is present
19
- ollama list | grep -q "granite4.1:3b" || {
20
- echo "[entrypoint] WARNING: granite4.1:3b not found in ollama; pulling..."
21
- ollama pull granite4.1:3b || true
22
- }
 
 
 
 
 
 
 
 
23
 
24
  exec uvicorn web.main:app --host 0.0.0.0 --port 7860 --log-level info
 
1
  #!/usr/bin/env sh
2
  # Start Ollama daemon in the background, wait for it to be ready,
3
  # then launch uvicorn on the HF Spaces default port.
4
+ #
5
+ # HF Spaces locks down /tmp for unprivileged users — write logs to
6
+ # $HOME (which we own) instead.
7
  set -e
8
 
9
+ LOG_FILE="$HOME/ollama.log"
10
+ ollama serve > "$LOG_FILE" 2>&1 &
11
  OLLAMA_PID=$!
12
 
13
+ # Wait for Ollama to be reachable (up to 60 s — first start can be slow
14
+ # on a cold container with persistent storage being mounted)
15
+ for i in $(seq 1 60); do
16
  if curl -sf http://127.0.0.1:11434/ > /dev/null 2>&1; then
17
+ echo "[entrypoint] ollama up (pid $OLLAMA_PID) after ${i}s"
18
  break
19
  fi
20
+ if ! kill -0 "$OLLAMA_PID" 2>/dev/null; then
21
+ echo "[entrypoint] FATAL: ollama serve died. Last 40 lines of $LOG_FILE:"
22
+ tail -40 "$LOG_FILE" || true
23
+ exit 1
24
+ fi
25
  sleep 1
26
  done
27
 
28
+ if ! curl -sf http://127.0.0.1:11434/ > /dev/null 2>&1; then
29
+ echo "[entrypoint] FATAL: ollama did not become ready within 60s"
30
+ tail -40 "$LOG_FILE" || true
31
+ exit 1
32
+ fi
33
+
34
+ # Sanity check: Granite 4.1 model is present (baked in during build)
35
+ if ! ollama list | grep -q "granite4.1:3b"; then
36
+ echo "[entrypoint] WARNING: granite4.1:3b not found; pulling now (slow!)..."
37
+ ollama pull granite4.1:3b || echo "[entrypoint] pull failed; reconciler will fail"
38
+ fi
39
+
40
+ ollama list
41
 
42
  exec uvicorn web.main:app --host 0.0.0.0 --port 7860 --log-level info