#!/bin/bash
# Backend Startup Script with Error Handling

echo "🚀 Starting Backend Server..."
cd /media/pts/Website/PromptTech_Solution_Site/backend

# Activate virtual environment
source venv/bin/activate

# Kill any existing processes on port 8181
echo "Checking for existing processes..."
lsof -ti:8181 | xargs kill -9 2>/dev/null || true
sleep 1

# Start the backend
echo "Starting Uvicorn server on port 8181..."
uvicorn server:app --reload --host 0.0.0.0 --port 8181

# If interrupted, this will clean up
trap 'echo "⚠️  Backend stopped"; deactivate; exit 0' INT TERM
