This commit is contained in:
2025-09-26 17:15:54 +08:00
commit db0e5965ec
211 changed files with 40437 additions and 0 deletions

View File

@@ -0,0 +1,110 @@
#!/bin/bash
# Unified port management script
# Usage:
# ./port_manager.sh kill [port] - Kill processes on specific port (default: 3000)
# ./port_manager.sh clear - Clear all common development ports
# ./port_manager.sh check [port] - Check what's running on port
ACTION=${1:-help}
PORT=${2:-3000}
show_help() {
echo "🔧 Port Manager"
echo "Usage:"
echo " $0 kill [port] - Kill processes on specific port (default: 3000)"
echo " $0 clear - Clear all common development ports"
echo " $0 check [port] - Check what's running on port (default: 3000)"
echo " $0 help - Show this help"
}
kill_port() {
local port=$1
echo "🔍 Checking for processes using port $port..."
# Find processes using the specified port
PIDS=$(ss -tulpn 2>/dev/null | grep ":$port " | grep -o 'pid=[0-9]*' | cut -d'=' -f2 || true)
if [ -z "$PIDS" ]; then
echo "✅ Port $port is free"
return 0
fi
echo "📋 Found processes using port $port:"
for PID in $PIDS; do
PROCESS_INFO=$(ps -p $PID -o pid,ppid,cmd --no-headers 2>/dev/null || echo "$PID [process ended]")
echo " PID $PROCESS_INFO"
done
echo "💀 Killing processes on port $port..."
for PID in $PIDS; do
if kill -TERM $PID 2>/dev/null; then
echo " ✅ Terminated PID $PID"
sleep 1
# Check if still running, force kill if needed
if kill -0 $PID 2>/dev/null; then
kill -KILL $PID 2>/dev/null && echo " 🔥 Force killed PID $PID"
fi
else
echo " ❌ Failed to kill PID $PID"
fi
done
echo "✅ Port $port is now free"
}
clear_ports() {
echo "🧹 Clearing common development ports..."
PORTS=(3000 3001 8000 8001 8000 5000 5001)
for port in "${PORTS[@]}"; do
PIDS=$(ss -tulpn 2>/dev/null | grep ":$port " | grep -o 'pid=[0-9]*' | cut -d'=' -f2 || true)
if [ -n "$PIDS" ]; then
echo "💀 Killing processes on port $port..."
for PID in $PIDS; do
kill -KILL $PID 2>/dev/null && echo " ✅ Killed PID $PID" || echo " ❌ Failed to kill PID $PID"
done
else
echo "✅ Port $port is free"
fi
done
}
check_port() {
local port=$1
echo "🔍 Checking port $port..."
PIDS=$(ss -tulpn 2>/dev/null | grep ":$port " | grep -o 'pid=[0-9]*' | cut -d'=' -f2 || true)
if [ -z "$PIDS" ]; then
echo "✅ Port $port is free"
else
echo "📋 Port $port is in use by:"
for PID in $PIDS; do
PROCESS_INFO=$(ps -p $PID -o pid,ppid,cmd --no-headers 2>/dev/null || echo "$PID [process ended]")
echo " PID $PROCESS_INFO"
done
fi
}
case $ACTION in
kill)
kill_port $PORT
;;
clear)
clear_ports
;;
check)
check_port $PORT
;;
help)
show_help
;;
*)
echo "❌ Unknown action: $ACTION"
show_help
exit 1
;;
esac

View File

@@ -0,0 +1,98 @@
#!/bin/bash
# Agentic RAG Service Startup Script
set -e
# Configuration
PORT=${PORT:-8000}
HOST=${HOST:-127.0.0.1}
CONFIG_FILE="config.yaml"
# Colors for output
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m' # No Color
echo -e "${GREEN}🚀 Starting Agentic RAG Service${NC}"
# Check if config file exists
if [[ ! -f "$CONFIG_FILE" ]]; then
echo -e "${RED}❌ Configuration file '$CONFIG_FILE' not found!${NC}"
echo -e "${YELLOW}💡 Make sure config.yaml is in the root directory${NC}"
exit 1
fi
echo -e "${GREEN}✅ Found configuration file: $CONFIG_FILE${NC}"
# Check if port is available
echo -e "${GREEN}🔍 Checking port $PORT availability...${NC}"
PIDS=$(ss -tulpn 2>/dev/null | grep ":$PORT " | grep -o 'pid=[0-9]*' | cut -d'=' -f2 || true)
if [ -n "$PIDS" ]; then
echo -e "${YELLOW}⚠️ Port $PORT is in use by:${NC}"
for PID in $PIDS; do
PROCESS_INFO=$(ps -p $PID -o cmd --no-headers 2>/dev/null || echo "Unknown process")
echo -e "${YELLOW} PID $PID: $PROCESS_INFO${NC}"
done
echo -e "${YELLOW}💀 Stopping existing processes on port $PORT...${NC}"
for PID in $PIDS; do
if kill -TERM $PID 2>/dev/null; then
echo -e "${GREEN} ✅ Terminated PID $PID${NC}"
sleep 1
# Force kill if still running
if kill -0 $PID 2>/dev/null; then
kill -KILL $PID 2>/dev/null && echo -e "${GREEN} 🔥 Force killed PID $PID${NC}"
fi
fi
done
# Verify port is free
sleep 1
NEW_PIDS=$(ss -tulpn 2>/dev/null | grep ":$PORT " | grep -o 'pid=[0-9]*' | cut -d'=' -f2 || true)
if [ -z "$NEW_PIDS" ]; then
echo -e "${GREEN}✅ Port $PORT is now free${NC}"
else
echo -e "${RED}❌ Warning: Port $PORT may still be in use${NC}"
fi
else
echo -e "${GREEN}✅ Port $PORT is available${NC}"
fi
# Start the service
echo -e "${GREEN}🔄 Starting service on http://$HOST:$PORT${NC}"
if [[ "$1" == "--dev" ]]; then
echo -e "${YELLOW}🛠️ Development mode: auto-reload enabled${NC}"
uv run uvicorn service.main:app --host $HOST --port $PORT --reload
elif [[ "$1" == "--background" ]]; then
echo -e "${GREEN}🏃 Background mode${NC}"
nohup uv run uvicorn service.main:app --host $HOST --port $PORT > server.log 2>&1 &
SERVER_PID=$!
echo -e "${GREEN}✅ Service started with PID: $SERVER_PID${NC}"
echo -e "${GREEN}📋 Logs: tail -f server.log${NC}"
# Wait a moment and check if service is healthy
sleep 3
if curl -s http://$HOST:$PORT/health >/dev/null 2>&1; then
echo -e "${GREEN}🎉 Service is healthy and ready!${NC}"
echo -e "${GREEN}🌐 Health check: http://$HOST:$PORT/health${NC}"
echo -e "${GREEN}📖 API docs: http://$HOST:$PORT/docs${NC}"
else
echo -e "${RED}❌ Service health check failed${NC}"
echo -e "${YELLOW}📋 Check logs: tail server.log${NC}"
exit 1
fi
else
echo -e "${GREEN}🏃 Foreground mode (default)${NC}"
echo -e "${YELLOW}💡 Use --background to run in background, --dev for development mode${NC}"
echo -e "${GREEN}🌐 Service will be available at: http://$HOST:$PORT${NC}"
echo -e "${GREEN}📖 API docs: http://$HOST:$PORT/docs${NC}"
echo -e "${YELLOW}⚠️ Press Ctrl+C to stop the service${NC}"
echo ""
# Run in foreground
uv run uvicorn service.main:app --host $HOST --port $PORT
fi

View File

@@ -0,0 +1,70 @@
#!/bin/bash
# Smart web development startup script
# Automatically handles port conflicts and starts development server
set -e
WEB_DIR="web"
PORT=3000
echo "🚀 Starting web development server..."
# Change to web directory
if [ ! -d "$WEB_DIR" ]; then
echo "❌ Web directory '$WEB_DIR' not found"
exit 1
fi
cd "$WEB_DIR"
# Check if port is in use
echo "🔍 Checking port $PORT..."
PIDS=$(ss -tulpn 2>/dev/null | grep ":$PORT " | grep -o 'pid=[0-9]*' | cut -d'=' -f2 || true)
if [ -n "$PIDS" ]; then
echo "⚠️ Port $PORT is in use by:"
for PID in $PIDS; do
PROCESS_INFO=$(ps -p $PID -o cmd --no-headers 2>/dev/null || echo "Unknown process")
echo " PID $PID: $PROCESS_INFO"
done
echo "💀 Auto-killing processes on port $PORT..."
for PID in $PIDS; do
if kill -TERM $PID 2>/dev/null; then
echo " ✅ Terminated PID $PID"
sleep 1
# Force kill if still running
if kill -0 $PID 2>/dev/null; then
kill -KILL $PID 2>/dev/null && echo " 🔥 Force killed PID $PID"
fi
fi
done
# Verify port is free
sleep 1
NEW_PIDS=$(ss -tulpn 2>/dev/null | grep ":$PORT " | grep -o 'pid=[0-9]*' | cut -d'=' -f2 || true)
if [ -z "$NEW_PIDS" ]; then
echo "✅ Port $PORT is now free"
else
echo "⚠️ Warning: Port $PORT may still be in use"
fi
else
echo "✅ Port $PORT is available"
fi
echo ""
echo "📦 Installing dependencies..."
if ! pnpm install --silent; then
echo "❌ Failed to install dependencies"
exit 1
fi
echo ""
echo "🌐 Starting development server..."
echo " - Local: http://localhost:$PORT"
echo " - Network: http://$(hostname -I | awk '{print $1}'):$PORT"
echo ""
# Start the development server
exec pnpm dev

View File

@@ -0,0 +1,48 @@
#!/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