aki-008 commited on
Commit
b40a2bc
Β·
1 Parent(s): 0aaef94

fix: remove local postgres startup logic for render migration

Browse files
Files changed (1) hide show
  1. start.sh +9 -53
start.sh CHANGED
@@ -1,66 +1,21 @@
1
  #!/bin/bash
 
2
 
3
- # --- 1. Dynamic PostgreSQL Path Detection ---
4
- PG_BIN_DIR=$(find /usr/lib/postgresql -name pg_ctl | head -n 1 | xargs dirname)
5
- if [ -z "$PG_BIN_DIR" ]; then
6
- echo "❌ Error: Could not find PostgreSQL binaries."
7
- exit 1
8
- fi
9
- echo "βœ… Found PostgreSQL binaries at $PG_BIN_DIR"
10
- export PATH="$PG_BIN_DIR:$PATH"
11
-
12
- # --- 2. Set Critical Environment Variables ---
13
- export DATABASE_URL="postgresql+asyncpg://prepuser:password@127.0.0.1:5432/studentdb"
14
- export PGDATA=/home/user/postgres_data
15
  export HOME=/home/user
 
 
 
16
  export chroma_host="127.0.0.1"
17
  export chroma_port="8080"
18
  export chroma_collection="prepai_collection"
19
 
20
- # --- 3. Database Initialization ---
21
- if [ -d "$PGDATA" ] && [ ! -f "$PGDATA/PG_VERSION" ]; then
22
- echo "⚠️ $PGDATA exists but is not a valid cluster. Wiping..."
23
- rm -rf "$PGDATA"
24
- fi
25
-
26
- if [ ! -d "$PGDATA" ]; then
27
- echo "βš™οΈ Initializing database..."
28
- initdb -D "$PGDATA" --auth-local=trust --no-locale --encoding=UTF8
29
- fi
30
-
31
- # --- 4. Start PostgreSQL (With Socket Fix) ---
32
- echo "πŸš€ Starting PostgreSQL..."
33
- # FIX: -o "-k /tmp" forces the socket lock file to be in /tmp (writable) instead of /var/run (protected)
34
- pg_ctl -D "$PGDATA" -l /home/user/postgres.log -o "-k /tmp" start
35
-
36
- # Wait a moment for startup...
37
- sleep 3
38
-
39
- # Check if it is actually running
40
- if ! pg_isready -h 127.0.0.1 -p 5432; then
41
- echo "❌ PostgreSQL failed to start. Printing contents of postgres.log:"
42
- echo "----------------------------------------------------------------"
43
- cat /home/user/postgres.log
44
- echo "----------------------------------------------------------------"
45
- exit 1
46
- fi
47
-
48
- echo "βœ… PostgreSQL is up and accepting connections!"
49
-
50
- # --- 5. User & DB Setup ---
51
- echo "πŸ› οΈ Configuring Database..."
52
- psql -h 127.0.0.1 -d postgres -tAc "SELECT 1 FROM pg_roles WHERE rolname='prepuser'" | grep -q 1 || \
53
- psql -h 127.0.0.1 -d postgres -c "CREATE USER prepuser WITH PASSWORD 'password';"
54
-
55
- psql -h 127.0.0.1 -d postgres -tAc "SELECT 1 FROM pg_database WHERE datname='studentdb'" | grep -q 1 || \
56
- createdb -h 127.0.0.1 -O prepuser studentdb
57
-
58
- # --- 6. ChromaDB Setup ---
59
  echo "🎨 Setting up ChromaDB..."
60
  mkdir -p ./chroma_store
61
  chroma run --host 0.0.0.0 --port 8080 --path ./chroma_store &
62
 
63
- # --- 7. Nginx Setup (Non-root) ---
64
  echo "🌐 Starting Nginx..."
65
  mkdir -p /tmp/nginx/body /tmp/nginx/proxy /tmp/nginx/fastcgi /tmp/nginx/uwsgi /tmp/nginx/scgi
66
 
@@ -99,7 +54,8 @@ EOF
99
 
100
  nginx -c /tmp/nginx.conf &
101
 
102
- # --- 8. Start Backend ---
103
  echo "🐍 Starting Backend..."
104
  cd Backend
 
105
  python run.py
 
1
  #!/bin/bash
2
+ set -e
3
 
4
+ # --- 1. Set Environment Variables ---
 
 
 
 
 
 
 
 
 
 
 
5
  export HOME=/home/user
6
+ # Note: DATABASE_URL is automatically provided by Hugging Face Secrets (pointing to 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 ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  echo "🎨 Setting up ChromaDB..."
15
  mkdir -p ./chroma_store
16
  chroma run --host 0.0.0.0 --port 8080 --path ./chroma_store &
17
 
18
+ # --- 3. Start Nginx (Non-root Mode) ---
19
  echo "🌐 Starting Nginx..."
20
  mkdir -p /tmp/nginx/body /tmp/nginx/proxy /tmp/nginx/fastcgi /tmp/nginx/uwsgi /tmp/nginx/scgi
21
 
 
54
 
55
  nginx -c /tmp/nginx.conf &
56
 
57
+ # --- 4. Start Backend ---
58
  echo "🐍 Starting Backend..."
59
  cd Backend
60
+ # The app will connect to the Render DB using the DATABASE_URL secret
61
  python run.py