aki-008 commited on
Commit
e183d08
Β·
1 Parent(s): f316317

Update start.sh: added health checks for ChromaDB to prevent 502 errors

Browse files
Files changed (1) hide show
  1. start.sh +20 -6
start.sh CHANGED
@@ -3,18 +3,19 @@ set -e
3
 
4
  # --- 1. Set Environment Variables ---
5
  export HOME=/home/user
6
- # DATABASE_URL is provided by Hugging Face Secrets (Render)
 
7
 
8
- # ChromaDB settings
9
  export chroma_host="127.0.0.1"
10
  export chroma_port="8080"
11
  export chroma_collection="prepai_collection"
 
12
 
13
- # --- 2. Start ChromaDB (Using /tmp for permissions) ---
14
  echo "🎨 Setting up ChromaDB..."
15
- # FIX: Use /tmp because the app root is read-only for non-root users
16
- export CHROMA_PATH="/tmp/chroma_store"
17
  mkdir -p "$CHROMA_PATH"
 
18
  chroma run --host 0.0.0.0 --port 8080 --path "$CHROMA_PATH" &
19
 
20
  # --- 3. Start Nginx (Non-root Mode) ---
@@ -56,7 +57,20 @@ EOF
56
 
57
  nginx -c /tmp/nginx.conf &
58
 
59
- # --- 4. Start Backend ---
 
 
 
 
 
 
 
 
 
 
 
 
60
  echo "🐍 Starting Backend..."
61
  cd Backend
 
62
  python run.py
 
3
 
4
  # --- 1. Set Environment Variables ---
5
  export HOME=/home/user
6
+ # DATABASE_URL, SECRET_KEY, VAPI_PUBLIC_KEY, and GROQ_API_KEY
7
+ # must be set in Hugging Face Space Secrets.
8
 
9
+ # ChromaDB Internal Settings
10
  export chroma_host="127.0.0.1"
11
  export chroma_port="8080"
12
  export chroma_collection="prepai_collection"
13
+ export CHROMA_PATH="/tmp/chroma_store"
14
 
15
+ # --- 2. Start ChromaDB (Background) ---
16
  echo "🎨 Setting up ChromaDB..."
 
 
17
  mkdir -p "$CHROMA_PATH"
18
+ # We use the internal 8080 port for ChromaDB
19
  chroma run --host 0.0.0.0 --port 8080 --path "$CHROMA_PATH" &
20
 
21
  # --- 3. Start Nginx (Non-root Mode) ---
 
57
 
58
  nginx -c /tmp/nginx.conf &
59
 
60
+ # --- 4. Wait for Services to be Ready ---
61
+ # The 502 error often happens because Backend starts before ChromaDB is listening.
62
+ echo "⏳ Waiting for ChromaDB to be responsive on port 8080..."
63
+ # Uses the built-in 'timeout' and '/dev/tcp' to check port status
64
+ timeout 30s bash -c 'until printf "" 2>>/dev/null >>/dev/tcp/127.0.0.1/8080; do sleep 1; done'
65
+
66
+ if [ $? -ne 0 ]; then
67
+ echo "❌ Error: ChromaDB failed to start within 30 seconds."
68
+ exit 1
69
+ fi
70
+ echo "βœ… ChromaDB is ready."
71
+
72
+ # --- 5. Start Backend ---
73
  echo "🐍 Starting Backend..."
74
  cd Backend
75
+ # Note: Ensure your FastAPI app listens on 127.0.0.1:8000
76
  python run.py