nxtgauge-backend-rust/start-services.sh

67 lines
2.5 KiB
Bash
Raw Normal View History

#!/bin/bash
set -e
set -a
source .env
set +a
# ── Initialize PostgreSQL database if needed ────────────────────────────────────
echo "Initializing database..."
# Use DATABASE_URL from .env to run init script
export PGPASSWORD=${POSTGRES_PASSWORD:-nxtgauge_dev}
# Check if database is accessible and if the 'roles' table exists as a heuristic
if psql "${DATABASE_URL:-postgresql://nxtgauge:${POSTGRES_PASSWORD:-nxtgauge_dev}@localhost:5432/nxtgauge_db}" -c '\q' 2>/dev/null; then
# Try to see if the schema is already initialized (check for 'roles' table)
if ! psql "${DATABASE_URL:-postgresql://nxtgauge:${POSTGRES_PASSWORD:-nxtgauge_dev}@localhost:5432/nxtgauge_db}" -t -c "SELECT to_regname('roles');" 2>/dev/null | grep -q '^roles$'; then
echo "Applying database schema..."
psql "${DATABASE_URL:-postgresql://nxtgauge:${POSTGRES_PASSWORD:-nxtgauge_dev}@localhost:5432/nxtgauge_db}" -f scripts/init-db.sql
else
echo "Database schema already initialized."
fi
else
echo "ERROR: Cannot connect to PostgreSQL. Make sure PostgreSQL is running on localhost:5432."
echo "Start PostgreSQL and try again."
exit 1
fi
echo "Building workspace..."
cargo build --workspace
echo "Stopping any previously running services..."
pkill -f "target/debug/gateway" || true
pkill -f "target/debug/users" || true
pkill -f "target/debug/companies" || true
pkill -f "target/debug/job_seekers" || true
pkill -f "target/debug/customers" || true
pkill -f "target/debug/photographers" || true
pkill -f "target/debug/makeup_artists" || true
pkill -f "target/debug/tutors" || true
pkill -f "target/debug/developers" || true
pkill -f "target/debug/video_editors" || true
pkill -f "target/debug/graphic_designers" || true
pkill -f "target/debug/social_media_managers" || true
pkill -f "target/debug/fitness_trainers" || true
pkill -f "target/debug/catering_services" || true
2026-04-06 01:47:10 +02:00
pkill -f "target/debug/ugc_content_creators" || true
pkill -f "target/debug/employees" || true
apps=(
"gateway" "users" "companies" "job_seekers" "customers"
"photographers" "makeup_artists" "tutors" "developers" "video_editors"
2026-04-06 01:47:10 +02:00
"graphic_designers" "social_media_managers" "fitness_trainers" "catering_services"
"ugc_content_creators" "employees"
)
for app in "${apps[@]}"; do
2026-04-06 01:47:10 +02:00
if [[ -x "./target/debug/$app" ]]; then
echo "Starting $app..."
nohup ./target/debug/$app > "$app.log" 2>&1 &
else
echo "Skipping $app (binary not found at ./target/debug/$app)"
fi
done
2026-04-06 01:47:10 +02:00
echo "All available services booted up!"