strat-gameplay-webapp/stop-services.sh
Cal Corum 6e3aad9fdf CLAUDE: Add developer utilities and access control documentation
Added helper scripts and documentation for improved developer experience:

1. ACCESS_CONTROL.md
   - Comprehensive Discord whitelist documentation
   - Configuration examples and security best practices
   - Troubleshooting guide for common access issues
   - Details both OAuth and test token protection points

2. start-services.sh
   - One-command startup for backend + frontend
   - Logs to logs/ directory with PIDs tracked
   - Displays URLs and helpful information
   - 3-second backend initialization delay

3. stop-services.sh
   - Clean shutdown with process tree killing
   - Removes orphaned processes by pattern matching
   - Graceful TERM followed by KILL if needed
   - Cleans up PID files

These utilities streamline local development by:
- Reducing manual startup steps
- Ensuring clean shutdown (no orphaned processes)
- Providing clear access control guidance

Scripts are now executable and ready to use:
  ./start-services.sh
  ./stop-services.sh

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-26 22:25:19 -06:00

100 lines
2.7 KiB
Bash
Executable File

#!/bin/bash
# Stop both backend and frontend services
# Enhanced to kill entire process trees and clean up orphans
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
LOG_DIR="$SCRIPT_DIR/logs"
echo "🛑 Stopping SBA Gameplay Services..."
echo ""
# Function to kill process tree
kill_tree() {
local pid=$1
local sig=${2:-TERM}
# Get all child PIDs
local children=$(pgrep -P "$pid" 2>/dev/null || true)
# Kill children first
for child in $children; do
kill_tree "$child" "$sig"
done
# Kill the parent
if ps -p "$pid" > /dev/null 2>&1; then
kill -"$sig" "$pid" 2>/dev/null || true
fi
}
# Stop Backend
if [ -f "$LOG_DIR/backend.pid" ]; then
BACKEND_PID=$(cat "$LOG_DIR/backend.pid")
if ps -p "$BACKEND_PID" > /dev/null 2>&1; then
echo "📡 Stopping Backend (PID: $BACKEND_PID)..."
kill_tree "$BACKEND_PID" TERM
sleep 1
# Force kill if still running
if ps -p "$BACKEND_PID" > /dev/null 2>&1; then
kill_tree "$BACKEND_PID" KILL
fi
echo " ✓ Backend stopped"
else
echo " ⚠ Backend process not found"
fi
rm -f "$LOG_DIR/backend.pid"
else
echo " ⚠ No backend PID file found"
fi
echo ""
# Stop Frontend
if [ -f "$LOG_DIR/frontend.pid" ]; then
FRONTEND_PID=$(cat "$LOG_DIR/frontend.pid")
if ps -p "$FRONTEND_PID" > /dev/null 2>&1; then
echo "🎨 Stopping Frontend (PID: $FRONTEND_PID)..."
kill_tree "$FRONTEND_PID" TERM
sleep 1
# Force kill if still running
if ps -p "$FRONTEND_PID" > /dev/null 2>&1; then
kill_tree "$FRONTEND_PID" KILL
fi
echo " ✓ Frontend stopped"
else
echo " ⚠ Frontend process not found"
fi
rm -f "$LOG_DIR/frontend.pid"
else
echo " ⚠ No frontend PID file found"
fi
echo ""
# Aggressive cleanup: kill ALL related processes by pattern matching
echo "🔍 Checking for any remaining processes..."
# Kill all uvicorn processes for this app
BACKEND_PIDS=$(pgrep -f "uvicorn.*app\.main" 2>/dev/null || true)
if [ -n "$BACKEND_PIDS" ]; then
echo " Found orphaned backend processes: $BACKEND_PIDS"
for pid in $BACKEND_PIDS; do
kill_tree "$pid" KILL
done
echo " ✓ Killed orphaned backend processes"
fi
# Kill all nuxt dev processes in this directory
FRONTEND_PIDS=$(pgrep -f "nuxt.*dev" | while read pid; do
if ps -p $pid -o args= | grep -q "$SCRIPT_DIR/frontend-sba"; then
echo $pid
fi
done)
if [ -n "$FRONTEND_PIDS" ]; then
echo " Found orphaned frontend processes: $FRONTEND_PIDS"
for pid in $FRONTEND_PIDS; do
kill_tree "$pid" KILL
done
echo " ✓ Killed orphaned frontend processes"
fi
echo "✅ Services stopped successfully!"