Files
gangyan/langchain-chat/stop_quick.sh

54 lines
1.3 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# 快速停止 Python 后端服务脚本(无需确认)
# 默认端口
DEFAULT_PORT=7861
# 颜色定义
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m'
echo -e "${YELLOW}正在查找并停止 Python 后端进程...${NC}"
# 方法1: 通过进程名查找
PIDS=$(ps aux | grep "[p]ython.*startup.py -a" | awk '{print $2}')
# 方法2: 如果方法1没找到通过端口查找
if [ -z "$PIDS" ]; then
PIDS=$(lsof -ti:${DEFAULT_PORT} 2>/dev/null)
fi
if [ -z "$PIDS" ]; then
echo -e "${RED}未找到运行中的 Python 后端进程${NC}"
exit 0
fi
# 显示找到的进程
echo -e "${GREEN}找到以下进程:${NC}"
ps aux | grep "[p]ython.*startup.py -a" | grep -v grep
# 停止进程
for PID in $PIDS; do
if [ -n "$PID" ]; then
echo -e "${YELLOW}正在停止进程 $PID...${NC}"
kill $PID 2>/dev/null
fi
done
# 等待进程结束
sleep 2
# 检查是否还有进程在运行,如果有则强制终止
REMAINING=$(ps aux | grep "[p]ython.*startup.py -a" | awk '{print $2}')
if [ -n "$REMAINING" ]; then
echo -e "${YELLOW}强制终止剩余进程...${NC}"
for PID in $REMAINING; do
kill -9 $PID 2>/dev/null
echo -e "${GREEN}已强制终止进程 $PID${NC}"
done
fi
echo -e "${GREEN}✓ 所有进程已停止${NC}"