Files
siemens_ragas/stop.sh

69 lines
1.7 KiB
Bash
Raw Permalink 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.

#!/usr/bin/env bash
# stop.sh — 停止 Siemens RAGAS 后台 Web 服务
# 用法bash stop.sh
set -uo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
# ── 颜色输出 ──────────────────────────────────────────────────────
if [ -t 1 ]; then
GREEN='\033[0;32m'; YELLOW='\033[1;33m'; RED='\033[0;31m'; CYAN='\033[0;36m'; NC='\033[0m'
else
GREEN=''; YELLOW=''; RED=''; CYAN=''; NC=''
fi
ok() { echo -e "${GREEN}[OK]${NC} $*"; }
warn() { echo -e "${YELLOW}[WARN]${NC} $*"; }
err() { echo -e "${RED}[ERROR]${NC} $*" >&2; }
echo ""
echo -e "${CYAN} Siemens RAGAS Console — 停止服务${NC}"
echo ""
PID_FILE="$SCRIPT_DIR/.server.pid"
if [ ! -f "$PID_FILE" ]; then
warn "未找到 .server.pid服务可能未启动或已停止"
exit 0
fi
PID=$(cat "$PID_FILE")
if ! kill -0 "$PID" 2>/dev/null; then
warn "进程 $PID 已不存在,清理 PID 文件"
rm -f "$PID_FILE"
exit 0
fi
# 优雅停止SIGTERM
echo -e " 正在停止进程 (PID=$PID)..."
kill "$PID" 2>/dev/null || true
# 等待最多 5 秒
for i in 1 2 3 4 5; do
sleep 1
if ! kill -0 "$PID" 2>/dev/null; then
break
fi
echo -e " 等待进程退出... ($i/5)"
done
# 若进程仍存在,强制终止
if kill -0 "$PID" 2>/dev/null; then
warn "进程未响应,强制终止 (SIGKILL)..."
kill -9 "$PID" 2>/dev/null || true
sleep 1
fi
rm -f "$PID_FILE"
if kill -0 "$PID" 2>/dev/null; then
err "无法停止进程 $PID请手动执行kill -9 $PID"
exit 1
else
ok "服务已停止"
echo ""
fi