Files
personal_development/ServerManagerWebApp/stop_app.sh
T
2026-01-09 19:24:41 +00:00

44 lines
1.2 KiB
Bash
Executable File

#!/bin/bash
# Signal scan cancellation
mkdir -p backend/logs
echo "cancel" > backend/logs/duplicates_scan.cancel
sleep 1
PROJECT_ROOT=$(pwd)
PID_FILE="$PROJECT_ROOT/.server_manager.pids"
echo "Stopping application..."
# 1. Kill by PID file
if [ -f "$PID_FILE" ]; then
while read pid; do
if [ -n "$pid" ] && ps -p $pid > /dev/null; then
echo "Killing process $pid from pidfile..."
kill $pid 2>/dev/null
fi
done < "$PID_FILE"
rm "$PID_FILE"
fi
# 2. Safety Net: Kill orphaned Huey consumers
echo "Checking for orphaned Huey consumers..."
pkill -f "huey_consumer" 2>/dev/null
# 3. Safety Net: Kill processes on port 8000 (Backend) and 5173 (Frontend)
echo "Ensuring ports are free..."
if command -v fuser >/dev/null 2>&1; then
fuser -k 8000/tcp >/dev/null 2>&1
fuser -k 5173/tcp >/dev/null 2>&1
else
# Fallback to lsof if fuser is missing (though we checked it exists)
if command -v lsof >/dev/null 2>&1; then
PIDS_8000=$(lsof -t -i:8000)
if [ -n "$PIDS_8000" ]; then kill $PIDS_8000 2>/dev/null; fi
PIDS_5173=$(lsof -t -i:5173)
if [ -n "$PIDS_5173" ]; then kill $PIDS_5173 2>/dev/null; fi
fi
fi
echo "Application stopped and ports cleared."