#!/bin/bash
# Iqra Path Server Startup Script
# Run with: ./start_server.sh

cd /Users/sansan/dev/iqra-path
source venv/bin/activate

echo "============================================"
echo "  Iqra Path Server"
echo "============================================"
echo ""

# Kill existing instances
pkill -f "gunicorn" 2>/dev/null
pkill -f "python run.py" 2>/dev/null
sleep 1

# Start with caffeinate to prevent Mac sleep
echo "Starting server..."
echo ""
echo "Local Access:    http://localhost:2222"
echo "Intranet Access: http://172.16.4.233:2222"
echo "Public Access:   http://103.78.24.250:2222 (requires port forwarding)"
echo ""
echo "Press Ctrl+C to stop the server."
echo "============================================"
echo ""

# Use caffeinate to prevent sleep, gunicorn for production
caffeinate -dimsu gunicorn \
    --bind 0.0.0.0:2222 \
    --workers 4 \
    --threads 2 \
    --timeout 120 \
    --access-logfile - \
    --error-logfile - \
    --log-level info \
    "app:create_app()"
