aki-008 commited on
Commit Β·
f6e5ff7
1
Parent(s): d430e0d
fix: debug mode for postgres startup failure
Browse files
start.sh
CHANGED
|
@@ -1,14 +1,11 @@
|
|
| 1 |
#!/bin/bash
|
| 2 |
-
set -e # Exit immediately if any command fails
|
| 3 |
|
| 4 |
# --- 1. Dynamic PostgreSQL Path Detection ---
|
| 5 |
PG_BIN_DIR=$(find /usr/lib/postgresql -name pg_ctl | head -n 1 | xargs dirname)
|
| 6 |
-
|
| 7 |
if [ -z "$PG_BIN_DIR" ]; then
|
| 8 |
echo "β Error: Could not find PostgreSQL binaries."
|
| 9 |
exit 1
|
| 10 |
fi
|
| 11 |
-
|
| 12 |
echo "β
Found PostgreSQL binaries at $PG_BIN_DIR"
|
| 13 |
export PATH="$PG_BIN_DIR:$PATH"
|
| 14 |
|
|
@@ -16,14 +13,13 @@ export PATH="$PG_BIN_DIR:$PATH"
|
|
| 16 |
export DATABASE_URL="postgresql+asyncpg://prepuser:password@127.0.0.1:5432/studentdb"
|
| 17 |
export PGDATA=/home/user/postgres_data
|
| 18 |
export HOME=/home/user
|
| 19 |
-
# ChromaDB settings
|
| 20 |
export chroma_host="127.0.0.1"
|
| 21 |
export chroma_port="8080"
|
| 22 |
export chroma_collection="prepai_collection"
|
| 23 |
|
| 24 |
# --- 3. Database Initialization ---
|
| 25 |
if [ -d "$PGDATA" ] && [ ! -f "$PGDATA/PG_VERSION" ]; then
|
| 26 |
-
echo "β οΈ $PGDATA exists but is not a valid cluster. Wiping
|
| 27 |
rm -rf "$PGDATA"
|
| 28 |
fi
|
| 29 |
|
|
@@ -32,22 +28,32 @@ if [ ! -d "$PGDATA" ]; then
|
|
| 32 |
initdb -D "$PGDATA" --auth-local=trust --no-locale --encoding=UTF8
|
| 33 |
fi
|
| 34 |
|
| 35 |
-
# --- 4. Start PostgreSQL
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
echo "π Starting PostgreSQL..."
|
| 37 |
-
#
|
| 38 |
-
|
| 39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
cat /home/user/postgres.log
|
|
|
|
| 41 |
exit 1
|
| 42 |
fi
|
| 43 |
|
| 44 |
-
|
| 45 |
-
echo "β³ Waiting for PostgreSQL to accept connections..."
|
| 46 |
-
until pg_isready -h 127.0.0.1 -p 5432; do
|
| 47 |
-
echo " ...waiting for DB..."
|
| 48 |
-
sleep 2
|
| 49 |
-
done
|
| 50 |
-
echo "β
PostgreSQL is up!"
|
| 51 |
|
| 52 |
# --- 5. User & DB Setup ---
|
| 53 |
echo "π οΈ Configuring Database..."
|
|
@@ -62,13 +68,9 @@ echo "π¨ Setting up ChromaDB..."
|
|
| 62 |
mkdir -p ./chroma_store
|
| 63 |
chroma run --host 0.0.0.0 --port 8080 --path ./chroma_store &
|
| 64 |
|
| 65 |
-
# --- 7. Nginx Setup ---
|
| 66 |
echo "π Starting Nginx..."
|
| 67 |
-
mkdir -p /tmp/nginx/body
|
| 68 |
-
/tmp/nginx/proxy \
|
| 69 |
-
/tmp/nginx/fastcgi \
|
| 70 |
-
/tmp/nginx/uwsgi \
|
| 71 |
-
/tmp/nginx/scgi
|
| 72 |
|
| 73 |
cat <<EOF > /tmp/nginx.conf
|
| 74 |
worker_processes 1;
|
|
@@ -89,13 +91,11 @@ http {
|
|
| 89 |
server {
|
| 90 |
listen 7860;
|
| 91 |
server_name localhost;
|
| 92 |
-
|
| 93 |
location / {
|
| 94 |
root /usr/share/nginx/html;
|
| 95 |
index index.html index.htm;
|
| 96 |
try_files \$uri \$uri/ /index.html;
|
| 97 |
}
|
| 98 |
-
|
| 99 |
location /api/v1/ {
|
| 100 |
proxy_pass http://127.0.0.1:8000/api/v1/;
|
| 101 |
proxy_set_header Host \$host;
|
|
|
|
| 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 |
|
|
|
|
| 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 |
|
|
|
|
| 28 |
initdb -D "$PGDATA" --auth-local=trust --no-locale --encoding=UTF8
|
| 29 |
fi
|
| 30 |
|
| 31 |
+
# --- 4. Configure & Start PostgreSQL ---
|
| 32 |
+
# FIX: Explicitly set the socket directory in the config file to avoid /var/run permissions issues
|
| 33 |
+
if ! grep -q "unix_socket_directories" "$PGDATA/postgresql.conf"; then
|
| 34 |
+
echo "unix_socket_directories = '/tmp'" >> "$PGDATA/postgresql.conf"
|
| 35 |
+
fi
|
| 36 |
+
|
| 37 |
+
# Remove any stale lock files from previous crashes
|
| 38 |
+
rm -f "$PGDATA/postmaster.pid"
|
| 39 |
+
|
| 40 |
echo "π Starting PostgreSQL..."
|
| 41 |
+
# Try to start. If it fails, we continue (no set -e) so we can print logs.
|
| 42 |
+
pg_ctl -D "$PGDATA" -l /home/user/postgres.log start
|
| 43 |
+
|
| 44 |
+
# Wait a moment for startup...
|
| 45 |
+
sleep 3
|
| 46 |
+
|
| 47 |
+
# Check if it is actually running
|
| 48 |
+
if ! pg_isready -h 127.0.0.1 -p 5432; then
|
| 49 |
+
echo "β PostgreSQL failed to start. Printing contents of postgres.log:"
|
| 50 |
+
echo "----------------------------------------------------------------"
|
| 51 |
cat /home/user/postgres.log
|
| 52 |
+
echo "----------------------------------------------------------------"
|
| 53 |
exit 1
|
| 54 |
fi
|
| 55 |
|
| 56 |
+
echo "β
PostgreSQL is up and accepting connections!"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
|
| 58 |
# --- 5. User & DB Setup ---
|
| 59 |
echo "π οΈ Configuring Database..."
|
|
|
|
| 68 |
mkdir -p ./chroma_store
|
| 69 |
chroma run --host 0.0.0.0 --port 8080 --path ./chroma_store &
|
| 70 |
|
| 71 |
+
# --- 7. Nginx Setup (Non-root) ---
|
| 72 |
echo "π Starting Nginx..."
|
| 73 |
+
mkdir -p /tmp/nginx/body /tmp/nginx/proxy /tmp/nginx/fastcgi /tmp/nginx/uwsgi /tmp/nginx/scgi
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
|
| 75 |
cat <<EOF > /tmp/nginx.conf
|
| 76 |
worker_processes 1;
|
|
|
|
| 91 |
server {
|
| 92 |
listen 7860;
|
| 93 |
server_name localhost;
|
|
|
|
| 94 |
location / {
|
| 95 |
root /usr/share/nginx/html;
|
| 96 |
index index.html index.htm;
|
| 97 |
try_files \$uri \$uri/ /index.html;
|
| 98 |
}
|
|
|
|
| 99 |
location /api/v1/ {
|
| 100 |
proxy_pass http://127.0.0.1:8000/api/v1/;
|
| 101 |
proxy_set_header Host \$host;
|