#!/bin/bash
cd /root/cma-management/backend
PID=$(lsof -ti :8010 2>/dev/null)
if [ -n "$PID" ]; then
    kill $PID 2>/dev/null
    sleep 1
    kill -9 $PID 2>/dev/null
    sleep 1
fi
nohup uvicorn app.main:app --host 0.0.0.0 --port 8010 > /tmp/cma-backend.log 2>&1 &
echo "PID=$!"
sleep 3
lsof -i :8010
echo "=== LOG ==="
tail -5 /tmp/cma-backend.log