#!/bin/bash # Agentic RAG Service Stop Script set -e # Colors for output GREEN='\033[0;32m' YELLOW='\033[1;33m' RED='\033[0;31m' NC='\033[0m' # No Color echo -e "${YELLOW}🛑 Stopping Agentic RAG Service${NC}" # Default port PORT=${PORT:-8000} # Find and stop processes PIDS=$(pgrep -f "uvicorn.*service.main.*$PORT" 2>/dev/null || true) if [[ -z "$PIDS" ]]; then echo -e "${YELLOW}⚠️ No running service found on port $PORT${NC}" else echo -e "${GREEN}🔍 Found service processes: $PIDS${NC}" # Stop the processes pkill -f "uvicorn.*service.main.*$PORT" 2>/dev/null || true # Wait a moment for graceful shutdown sleep 2 # Force kill if still running REMAINING=$(pgrep -f "uvicorn.*service.main.*$PORT" 2>/dev/null || true) if [[ -n "$REMAINING" ]]; then echo -e "${YELLOW}🔧 Force killing remaining processes...${NC}" pkill -9 -f "uvicorn.*service.main.*$PORT" 2>/dev/null || true fi echo -e "${GREEN}✅ Service stopped successfully${NC}" fi # Show current status if lsof -Pi :$PORT -sTCP:LISTEN -t >/dev/null 2>&1; then echo -e "${RED}❌ Port $PORT is still in use by another process${NC}" lsof -Pi :$PORT -sTCP:LISTEN else echo -e "${GREEN}✅ Port $PORT is now available${NC}" fi