#!/bin/bash
cd /home/dailyorderz/takeoff.bonyanplus.com

echo "Attempting forceful kill of uvicorn..."

# Extreme force kill
killall -9 uvicorn 2>/dev/null
killall -9 python 2>/dev/null
killall -9 python3 2>/dev/null
killall -9 python3.10 2>/dev/null
killall -9 python3.12 2>/dev/null

sleep 2

# Extra safety: use lsof if available
LSOF_PID=$(lsof -t -i:18283 2>/dev/null)
if [ -n "$LSOF_PID" ]; then
    kill -9 $LSOF_PID 2>/dev/null
fi

sleep 2

# Start fresh uvicorn
nohup setsid /home/dailyorderz/takeoff_venv/bin/python -m uvicorn main:app --host 127.0.0.1 --port 18283 > uvicorn.log 2>&1 < /dev/null &
echo "FastAPI uvicorn startup initiated with PID $!"
