#!/bin/bash # Smart web development startup script # Automatically handles port conflicts and starts development server set -e WEB_DIR="web" PORT=3000 echo "🚀 Starting web development server..." # Change to web directory if [ ! -d "$WEB_DIR" ]; then echo "❌ Web directory '$WEB_DIR' not found" exit 1 fi cd "$WEB_DIR" # Check if port is in use echo "🔍 Checking port $PORT..." PIDS=$(ss -tulpn 2>/dev/null | grep ":$PORT " | grep -o 'pid=[0-9]*' | cut -d'=' -f2 || true) if [ -n "$PIDS" ]; then echo "⚠️ Port $PORT is in use by:" for PID in $PIDS; do PROCESS_INFO=$(ps -p $PID -o cmd --no-headers 2>/dev/null || echo "Unknown process") echo " PID $PID: $PROCESS_INFO" done echo "💀 Auto-killing processes on port $PORT..." for PID in $PIDS; do if kill -TERM $PID 2>/dev/null; then echo " ✅ Terminated PID $PID" sleep 1 # Force kill if still running if kill -0 $PID 2>/dev/null; then kill -KILL $PID 2>/dev/null && echo " 🔥 Force killed PID $PID" fi fi done # Verify port is free sleep 1 NEW_PIDS=$(ss -tulpn 2>/dev/null | grep ":$PORT " | grep -o 'pid=[0-9]*' | cut -d'=' -f2 || true) if [ -z "$NEW_PIDS" ]; then echo "✅ Port $PORT is now free" else echo "⚠️ Warning: Port $PORT may still be in use" fi else echo "✅ Port $PORT is available" fi echo "" echo "📦 Installing dependencies..." if ! pnpm install --silent; then echo "❌ Failed to install dependencies" exit 1 fi echo "" echo "🌐 Starting development server..." echo " - Local: http://localhost:$PORT" echo " - Network: http://$(hostname -I | awk '{print $1}'):$PORT" echo "" # Start the development server exec pnpm dev