LPX55 commited on
Commit
ce3e736
·
verified ·
1 Parent(s): 3546d3d

Update entrypoint.sh

Browse files
Files changed (1) hide show
  1. entrypoint.sh +41 -8
entrypoint.sh CHANGED
@@ -1,19 +1,52 @@
1
  #!/bin/bash
2
 
 
 
 
 
 
 
 
 
 
 
 
3
  # Start Ollama server in the background
 
4
  ollama serve &
 
 
 
 
 
 
5
 
6
- # Wait for the server to be ready
7
  while ! nc -z localhost 7860; do
8
- echo "Waiting for Ollama server to start..."
 
 
 
 
9
  sleep 1
 
10
  done
11
 
12
- # Pull the model
 
 
13
  echo "Pulling the model..."
14
- ollama pull gemma3:27b-it-qat
15
- # ollama pull smollm:1.7b-instruct-v0.2-q6_K
16
- # hf.co/unsloth/phi-4-GGUF:Q8_0
 
 
 
 
 
 
 
 
17
 
18
- # Keep the container running
19
- wait
 
 
1
  #!/bin/bash
2
 
3
+ # Function to handle shutdown gracefully
4
+ cleanup() {
5
+ echo "Shutting down Ollama server..."
6
+ pkill -f "ollama serve"
7
+ exit 0
8
+ }
9
+
10
+
11
+ # Set up signal handlers for graceful shutdown
12
+ trap cleanup SIGTERM SIGINT
13
+
14
  # Start Ollama server in the background
15
+ echo "Starting Ollama server..."
16
  ollama serve &
17
+ OLLAMA_PID=$!
18
+
19
+ # Wait for the server to be ready with timeout
20
+ echo "Waiting for Ollama server to start..."
21
+ TIMEOUT=60
22
+ COUNTER=0
23
 
 
24
  while ! nc -z localhost 7860; do
25
+ if [ $COUNTER -ge $TIMEOUT ]; then
26
+ echo "ERROR: Ollama server failed to start within $TIMEOUT seconds"
27
+ exit 1
28
+ fi
29
+ echo "Waiting for Ollama server to start... ($COUNTER/$TIMEOUT)"
30
  sleep 1
31
+ ((COUNTER++))
32
  done
33
 
34
+ echo "Ollama server is ready!"
35
+
36
+ # Pull the model with error handling
37
  echo "Pulling the model..."
38
+ if ! ollama pull gemma3:270m; then
39
+ echo "ERROR: Failed to pull model smollm2:135m"
40
+ exit 1
41
+ fi
42
+
43
+ if ! ollama pull nomic-embed-text; then
44
+ echo "ERROR: Failed to pull model gemma3:1b"
45
+ exit 1
46
+ fi
47
+
48
+ echo "Model pulled successfully!"
49
 
50
+ # Keep the container running and wait for the ollama process
51
+ echo "Container is ready. Ollama server is running on port 7860."
52
+ wait $OLLAMA_PID