kangda/stop_websocket.sh
2025-05-30 11:40:27 +08:00

28 lines
644 B
Bash
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
# 日志目录
LOG_DIR="logs/websocket"
PID_FILE="$LOG_DIR/websocket.pid"
# 检查PID文件是否存在
if [ ! -f "$PID_FILE" ]; then
echo "找不到PID文件尝试通过进程名查找..."
PID=$(pgrep -f "run_websocket.py")
if [ -z "$PID" ]; then
echo "WebSocket客户端未在运行"
exit 0
fi
else
PID=$(cat "$PID_FILE")
fi
# 检查进程是否存在
if ps -p $PID > /dev/null; then
echo "正在停止WebSocket客户端 (PID: $PID)..."
kill $PID
rm -f "$PID_FILE"
echo "WebSocket客户端已停止"
else
echo "WebSocket客户端未在运行"
rm -f "$PID_FILE"
fi