tommytracx commited on
Commit
17fc73e
·
verified ·
1 Parent(s): 691ab4b

Create start.sh

Browse files
Files changed (1) hide show
  1. start.sh +29 -0
start.sh ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # start.sh
2
+ #!/bin/bash
3
+ set -e
4
+ LOG_FILE=/data/startup.log
5
+ mkdir -p /data && touch $LOG_FILE && chmod 644 $LOG_FILE
6
+ echo "Starting Ollama server at $(date)" >> $LOG_FILE
7
+ ollama serve >> $LOG_FILE 2>&1 &
8
+ sleep 15
9
+ MODELS_TO_PULL="${MODELS_TO_PULL:-gemma-3-270m}"
10
+ echo "Pulling models: $MODELS_TO_PULL" | tee -a $LOG_FILE
11
+ IFS=',' read -ra MODEL_ARRAY <<< "$MODELS_TO_PULL"
12
+ for model in "${MODEL_ARRAY[@]}"; do
13
+ echo "Pulling model $model..." | tee -a $LOG_FILE
14
+ for attempt in {1..3}; do
15
+ if ollama pull "$model" >> $LOG_FILE 2>&1; then
16
+ echo "Model $model pulled successfully" | tee -a $LOG_FILE
17
+ break
18
+ else
19
+ echo "Attempt $attempt: Failed to pull model $model, retrying in 10 seconds..." | tee -a $LOG_FILE
20
+ sleep 10
21
+ fi
22
+ if [ $attempt -eq 3 ]; then
23
+ echo "Error: Failed to pull model $model after 3 attempts" | tee -a $LOG_FILE
24
+ exit 1
25
+ fi
26
+ done
27
+ done
28
+ echo "Starting Gunicorn server at $(date)" | tee -a $LOG_FILE
29
+ exec gunicorn --bind 0.0.0.0:7860 --workers 1 --timeout 120 --log-level info app:app >> $LOG_FILE 2>&1