Update start.sh
Browse files
start.sh
CHANGED
|
@@ -4,6 +4,74 @@ set -e
|
|
| 4 |
# Hugging Face provides PORT; default to 7860 locally
|
| 5 |
export PORT="${PORT:-7860}"
|
| 6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
# Defaults for local in-container routing; can be overridden via env
|
| 8 |
export SUPERVISOR_API_URL="${SUPERVISOR_API_URL:-http://127.0.0.1:8080/api/v1/supervisor}"
|
| 9 |
export DATABASE_API_URL="${DATABASE_API_URL:-http://127.0.0.1:8080/api/v1/db}"
|
|
@@ -16,4 +84,4 @@ uvicorn src.api.app:app --host 0.0.0.0 --port 8080 &
|
|
| 16 |
sleep 2
|
| 17 |
|
| 18 |
# Run Gradio frontend
|
| 19 |
-
python src/frontend/gradio/app.py
|
|
|
|
| 4 |
# Hugging Face provides PORT; default to 7860 locally
|
| 5 |
export PORT="${PORT:-7860}"
|
| 6 |
|
| 7 |
+
# Locate PostgreSQL binaries (initdb/pg_ctl) even on versioned paths
|
| 8 |
+
PG_BIN=$(dirname $(find /usr/lib/postgresql -name initdb | head -n 1 2>/dev/null))
|
| 9 |
+
if [ -n "$PG_BIN" ]; then
|
| 10 |
+
export PATH="$PG_BIN:$PATH"
|
| 11 |
+
fi
|
| 12 |
+
|
| 13 |
+
# Normalize DB host: if set to 'db' (compose style), force localhost for single-container run
|
| 14 |
+
if [ "${POSTGRES_HOST}" = "db" ] || [ "${POSTGRES_HOST}" = "\"db\"" ] || [ -z "${POSTGRES_HOST}" ]; then
|
| 15 |
+
export POSTGRES_HOST="127.0.0.1"
|
| 16 |
+
fi
|
| 17 |
+
export POSTGRES_PORT="${POSTGRES_PORT:-5432}"
|
| 18 |
+
export POSTGRES_USER="${POSTGRES_USER:-agentic_user}"
|
| 19 |
+
export POSTGRES_PASSWORD="${POSTGRES_PASSWORD:-password123}"
|
| 20 |
+
export POSTGRES_DB="${POSTGRES_DB:-agentic_hr}"
|
| 21 |
+
|
| 22 |
+
echo "[start.sh] PORT=${PORT}"
|
| 23 |
+
echo "[start.sh] POSTGRES_HOST=${POSTGRES_HOST}"
|
| 24 |
+
echo "[start.sh] POSTGRES_PORT=${POSTGRES_PORT}"
|
| 25 |
+
echo "[start.sh] POSTGRES_USER=${POSTGRES_USER}"
|
| 26 |
+
echo "[start.sh] POSTGRES_DB=${POSTGRES_DB}"
|
| 27 |
+
|
| 28 |
+
# Start local Postgres if not already running
|
| 29 |
+
export PGDATA=/var/lib/postgresql/data
|
| 30 |
+
mkdir -p "$PGDATA"
|
| 31 |
+
chown -R postgres:postgres "$PGDATA"
|
| 32 |
+
mkdir -p /var/run/postgresql
|
| 33 |
+
chown postgres:postgres /var/run/postgresql
|
| 34 |
+
|
| 35 |
+
if [ ! -s "$PGDATA/PG_VERSION" ]; then
|
| 36 |
+
echo "[start.sh] Initializing postgres data dir..."
|
| 37 |
+
gosu postgres initdb -D "$PGDATA"
|
| 38 |
+
fi
|
| 39 |
+
|
| 40 |
+
echo "[start.sh] Starting postgres on port ${POSTGRES_PORT}..."
|
| 41 |
+
if ! gosu postgres pg_ctl -D "$PGDATA" -o "-p ${POSTGRES_PORT} -k /var/run/postgresql" -w start >> /var/log/postgres.log 2>&1; then
|
| 42 |
+
echo "[start.sh] Postgres failed to start. Last log lines:"
|
| 43 |
+
tail -n 100 /var/log/postgres.log || true
|
| 44 |
+
exit 1
|
| 45 |
+
fi
|
| 46 |
+
echo "[start.sh] Postgres started."
|
| 47 |
+
echo "[start.sh] Postgres last log lines:"
|
| 48 |
+
tail -n 50 /var/log/postgres.log || true
|
| 49 |
+
|
| 50 |
+
# Ensure user/db exist
|
| 51 |
+
gosu postgres psql -h 127.0.0.1 -p "${POSTGRES_PORT}" -v ON_ERROR_STOP=1 --command "DO \$\$
|
| 52 |
+
BEGIN
|
| 53 |
+
IF NOT EXISTS (SELECT FROM pg_catalog.pg_roles WHERE rolname = '${POSTGRES_USER}') THEN
|
| 54 |
+
CREATE ROLE ${POSTGRES_USER} LOGIN PASSWORD '${POSTGRES_PASSWORD}';
|
| 55 |
+
END IF;
|
| 56 |
+
END
|
| 57 |
+
\$\$;" || true
|
| 58 |
+
gosu postgres psql -h 127.0.0.1 -p "${POSTGRES_PORT}" -v ON_ERROR_STOP=1 --command "CREATE DATABASE ${POSTGRES_DB} OWNER ${POSTGRES_USER}" || true
|
| 59 |
+
echo "[start.sh] Postgres user/db ensured."
|
| 60 |
+
|
| 61 |
+
# Create tables if they don't exist
|
| 62 |
+
echo "[start.sh] Ensuring database tables exist..."
|
| 63 |
+
python - <<'PY'
|
| 64 |
+
import os
|
| 65 |
+
from src.database.candidates.models import Base
|
| 66 |
+
from src.database.candidates.client import engine
|
| 67 |
+
|
| 68 |
+
try:
|
| 69 |
+
Base.metadata.create_all(bind=engine)
|
| 70 |
+
print("[db-init] Tables ensured.")
|
| 71 |
+
except Exception as e:
|
| 72 |
+
print(f"[db-init] Failed to create tables: {e}")
|
| 73 |
+
PY
|
| 74 |
+
|
| 75 |
# Defaults for local in-container routing; can be overridden via env
|
| 76 |
export SUPERVISOR_API_URL="${SUPERVISOR_API_URL:-http://127.0.0.1:8080/api/v1/supervisor}"
|
| 77 |
export DATABASE_API_URL="${DATABASE_API_URL:-http://127.0.0.1:8080/api/v1/db}"
|
|
|
|
| 84 |
sleep 2
|
| 85 |
|
| 86 |
# Run Gradio frontend
|
| 87 |
+
python src/frontend/gradio/app.py
|