aki-008
commited on
Commit
·
3540614
1
Parent(s):
4aa09b2
fix: resolve pg_ctl path, export env vars, and fix nginx permissions
Browse files
start.sh
CHANGED
|
@@ -1,33 +1,84 @@
|
|
| 1 |
#!/bin/bash
|
| 2 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
export PGDATA=/home/user/postgres_data
|
| 4 |
|
| 5 |
-
|
|
|
|
| 6 |
echo "Initializing database..."
|
| 7 |
initdb -D "$PGDATA"
|
| 8 |
fi
|
| 9 |
|
| 10 |
echo "Starting PostgreSQL..."
|
| 11 |
-
# Start
|
| 12 |
-
pg_ctl -D "$PGDATA" -l /home/user/
|
|
|
|
| 13 |
|
| 14 |
-
#
|
| 15 |
-
|
|
|
|
| 16 |
|
| 17 |
-
#
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
-
#
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
-
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
-
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
-
#
|
|
|
|
| 32 |
cd Backend
|
| 33 |
python run.py
|
|
|
|
| 1 |
#!/bin/bash
|
| 2 |
+
|
| 3 |
+
# --- 1. Fix PostgreSQL Path ---
|
| 4 |
+
# Add common PostgreSQL bin paths to $PATH so 'initdb' and 'pg_ctl' are found
|
| 5 |
+
export PATH=/usr/lib/postgresql/17/bin:/usr/lib/postgresql/16/bin:/usr/lib/postgresql/15/bin:/usr/lib/postgresql/14/bin:$PATH
|
| 6 |
+
|
| 7 |
+
# --- 2. Set Critical Environment Variables (Fixes Pydantic Error) ---
|
| 8 |
+
export DATABASE_URL="postgresql+asyncpg://prepuser:password@127.0.0.1:5432/studentdb"
|
| 9 |
+
export chroma_host="127.0.0.1"
|
| 10 |
+
export chroma_port="8080"
|
| 11 |
+
export chroma_collection="prepai_collection"
|
| 12 |
export PGDATA=/home/user/postgres_data
|
| 13 |
|
| 14 |
+
# --- 3. Initialize & Start PostgreSQL ---
|
| 15 |
+
if [ ! -d "$PGDATA" ]; then
|
| 16 |
echo "Initializing database..."
|
| 17 |
initdb -D "$PGDATA"
|
| 18 |
fi
|
| 19 |
|
| 20 |
echo "Starting PostgreSQL..."
|
| 21 |
+
# Start DB in background
|
| 22 |
+
pg_ctl -D "$PGDATA" -l /home/user/postgres.log start
|
| 23 |
+
sleep 3
|
| 24 |
|
| 25 |
+
# Create User and Database if they don't exist
|
| 26 |
+
psql -h 127.0.0.1 -d postgres -c "CREATE USER prepuser WITH PASSWORD 'password';" || true
|
| 27 |
+
createdb -h 127.0.0.1 -O prepuser studentdb || true
|
| 28 |
|
| 29 |
+
# --- 4. Start Nginx (Non-Root Mode) ---
|
| 30 |
+
# Create temp directories for Nginx to write to (avoids permission errors)
|
| 31 |
+
mkdir -p /tmp/nginx/body \
|
| 32 |
+
/tmp/nginx/proxy \
|
| 33 |
+
/tmp/nginx/fastcgi \
|
| 34 |
+
/tmp/nginx/uwsgi \
|
| 35 |
+
/tmp/nginx/scgi
|
| 36 |
|
| 37 |
+
# Generate a non-root compatible nginx config on the fly
|
| 38 |
+
cat <<EOF > /tmp/nginx.conf
|
| 39 |
+
worker_processes 1;
|
| 40 |
+
daemon off;
|
| 41 |
+
pid /tmp/nginx.pid;
|
| 42 |
+
error_log /tmp/error.log;
|
| 43 |
+
events { worker_connections 1024; }
|
| 44 |
+
http {
|
| 45 |
+
include /etc/nginx/mime.types;
|
| 46 |
+
default_type application/octet-stream;
|
| 47 |
+
access_log /tmp/access.log;
|
| 48 |
+
client_body_temp_path /tmp/nginx/body;
|
| 49 |
+
proxy_temp_path /tmp/nginx/proxy;
|
| 50 |
+
fastcgi_temp_path /tmp/nginx/fastcgi;
|
| 51 |
+
uwsgi_temp_path /tmp/nginx/uwsgi;
|
| 52 |
+
scgi_temp_path /tmp/nginx/scgi;
|
| 53 |
|
| 54 |
+
server {
|
| 55 |
+
listen 7860;
|
| 56 |
+
server_name localhost;
|
| 57 |
+
|
| 58 |
+
location / {
|
| 59 |
+
root /usr/share/nginx/html;
|
| 60 |
+
index index.html index.htm;
|
| 61 |
+
try_files \$uri \$uri/ /index.html;
|
| 62 |
+
}
|
| 63 |
|
| 64 |
+
location /api/v1/ {
|
| 65 |
+
proxy_pass http://127.0.0.1:8000/api/v1/;
|
| 66 |
+
proxy_set_header Host \$host;
|
| 67 |
+
proxy_set_header X-Real-IP \$remote_addr;
|
| 68 |
+
}
|
| 69 |
+
}
|
| 70 |
+
}
|
| 71 |
+
EOF
|
| 72 |
+
|
| 73 |
+
# Start Nginx in the background using the custom config
|
| 74 |
+
echo "Starting Nginx..."
|
| 75 |
+
nginx -c /tmp/nginx.conf &
|
| 76 |
+
|
| 77 |
+
# --- 5. Start ChromaDB ---
|
| 78 |
+
echo "Starting ChromaDB..."
|
| 79 |
+
chroma run --host 0.0.0.0 --port 8080 --path ./chroma_store &
|
| 80 |
|
| 81 |
+
# --- 6. Start Backend ---
|
| 82 |
+
echo "Starting Backend..."
|
| 83 |
cd Backend
|
| 84 |
python run.py
|