File size: 1,195 Bytes
01f0289
 
41dda76
 
 
 
 
 
 
1d21b6c
41dda76
 
 
01f0289
41dda76
907b351
41dda76
 
 
 
 
 
01f0289
 
41dda76
 
 
 
 
01f0289
41dda76
01f0289
 
41dda76
 
 
01f0289
41dda76
 
 
 
 
d12b452
 
 
 
 
41dda76
01f0289
41dda76
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/bin/bash

# Function to handle shutdown gracefully
cleanup() {
    echo "Shutting down Ollama server..."
    pkill -f "ollama serve"
    exit 0
}


# Set up signal handlers for graceful shutdown
trap cleanup SIGTERM SIGINT

# Start Ollama server in the background
echo "Starting Ollama server..."
ollama serve &
OLLAMA_PID=$!

# Wait for the server to be ready with timeout
echo "Waiting for Ollama server to start..."
TIMEOUT=60
COUNTER=0

while ! nc -z localhost 7860; do
    if [ $COUNTER -ge $TIMEOUT ]; then
        echo "ERROR: Ollama server failed to start within $TIMEOUT seconds"
        exit 1
    fi
    echo "Waiting for Ollama server to start... ($COUNTER/$TIMEOUT)"
    sleep 1
    ((COUNTER++))
done

echo "Ollama server is ready!"

# Pull the model with error handling
echo "Pulling the model..."
if ! ollama pull gemma3:1b; then
    echo "ERROR: Failed to pull model gemma3:1b"
    exit 1
fi

if ! ollama pull nomic-embed-text; then
    echo "ERROR: Failed to pull model gemma3:1b"
    exit 1
fi

echo "Model pulled successfully!"

# Keep the container running and wait for the ollama process
echo "Container is ready. Ollama server is running on port 7860."
wait $OLLAMA_PID