rwadurian/backend/services/blockchain-service/scripts/stop-service.sh

45 lines
889 B
Bash

#!/bin/bash
# 停止 Blockchain Service
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m'
echo -e "${YELLOW}🛑 停止 Blockchain Service...${NC}"
# 查找监听 3012 端口的进程
PID=$(lsof -ti :3012)
if [ -z "$PID" ]; then
echo -e "${YELLOW}⚠️ Blockchain Service 未在运行${NC}"
exit 0
fi
echo "找到进程: PID=$PID"
# 尝试优雅停止
echo "发送 SIGTERM 信号..."
kill $PID
# 等待进程结束
for i in {1..10}; do
if ! kill -0 $PID 2>/dev/null; then
echo -e "${GREEN}✓ Blockchain Service 已停止${NC}"
exit 0
fi
sleep 1
echo -n "."
done
echo ""
echo -e "${YELLOW}⚠️ 进程未响应,强制停止...${NC}"
kill -9 $PID
if ! kill -0 $PID 2>/dev/null; then
echo -e "${GREEN}✓ Blockchain Service 已强制停止${NC}"
else
echo -e "${RED}✗ 无法停止进程${NC}"
exit 1
fi