File size: 1,983 Bytes
dee5d65
 
 
 
 
b61efb5
 
 
 
 
26ff678
b61efb5
dee5d65
 
b61efb5
 
dee5d65
b61efb5
 
e933f88
f9806c8
e933f88
b61efb5
0c64de0
b61efb5
 
 
 
 
 
dee5d65
b61efb5
0c64de0
b61efb5
0c64de0
b61efb5
0c64de0
b61efb5
0c64de0
b61efb5
 
 
 
e933f88
b61efb5
 
 
0c64de0
dee5d65
b61efb5
 
 
dee5d65
b61efb5
e933f88
 
dee5d65
 
b61efb5
 
dee5d65
 
e933f88
 
 
 
 
b61efb5
26ff678
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/bin/bash
set -e

echo "πŸš€ Starting Ollama + FastAPI Server..."

# Create ollama directory and config
mkdir -p /tmp/ollama
mkdir -p /tmp/ollama/logs

# Set ALL possible Ollama environment variables (force override)
export OLLAMA_HOME=/tmp/ollama
export OLLAMA_MODELS=/tmp/ollama/models
export OLLAMA_HOST=0.0.0.0:11434
export OLLAMA_ORIGINS="*"
export OLLAMA_KEEP_ALIVE=5m
export OLLAMA_DEBUG=1

echo "πŸ“ Environment check:"
echo "OLLAMA_HOME=$OLLAMA_HOME"
echo "Current directory: $(pwd)"

# Try to start Ollama with explicit environment (DON'T change directory)
echo "πŸ“‘ Starting Ollama with forced environment..."

# Start Ollama with environment explicitly set in the command
env OLLAMA_HOME=/tmp/ollama \
    OLLAMA_MODELS=/tmp/ollama/models \
    OLLAMA_HOST=0.0.0.0:11434 \
    OLLAMA_DATA_DIR=/tmp/ollama \
    ollama serve > /tmp/ollama/server.log 2>&1 &
OLLAMA_PID=$!

echo "πŸ“ Ollama PID: $OLLAMA_PID"
sleep 3

# Check if process is still running
if ps -p $OLLAMA_PID > /dev/null 2>&1; then
    echo "βœ… Ollama process still running"
else
    echo "❌ Ollama died again. Log contents:"
    cat /tmp/ollama/server.log 2>/dev/null || echo "No server log"
    echo "Trying alternative startup method..."
    
    # Alternative: Start ollama differently (DON'T change to /tmp/ollama directory)
    HOME=/tmp/ollama ollama serve > /tmp/ollama/alt.log 2>&1 &
    OLLAMA_PID=$!
    sleep 3
fi

# Test connection
echo "⏳ Testing connection..."
for i in {1..5}; do
    if curl -f http://127.0.0.1:11434/api/tags >/dev/null 2>&1; then
        echo "βœ… Ollama is responding!"
        # Start model download in background
        (ollama pull llama3.2:1b > /tmp/ollama/pull.log 2>&1 &) || true
        break
    fi
    echo "πŸ”„ Attempt $i/5 - Still waiting..."
    sleep 2
done

# MAKE SURE WE'RE IN THE RIGHT DIRECTORY for FastAPI
cd /app
echo "πŸ“ Changed to directory: $(pwd)"
echo "πŸ“ Files available: $(ls -la)"

echo "πŸš€ Starting FastAPI..."
python app.py