coze-studio/stop.sh

100 lines
3.0 KiB
Bash
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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
#
# Copyright 2025 coze-dev Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Coze Studio 关闭脚本
# 该脚本将优雅地停止所有正在运行的服务
set -e
echo "🛑 正在关闭 Coze Studio..."
# 获取脚本所在目录
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
# 停止前端开发服务器
echo "🔍 查找并停止前端开发服务器..."
FRONTEND_PIDS=$(pgrep -f "rushx dev" || echo "")
if [ -n "$FRONTEND_PIDS" ]; then
echo "🎯 发现前端进程: $FRONTEND_PIDS"
echo "$FRONTEND_PIDS" | xargs kill -TERM 2>/dev/null || true
sleep 2
# 强制终止未退出的进程
echo "$FRONTEND_PIDS" | xargs kill -KILL 2>/dev/null || true
echo "✅ 前端开发服务器已停止"
else
echo " 未发现运行中的前端开发服务器"
fi
# 停止 Node.js 相关进程
echo "🔍 查找并停止 Node.js 进程..."
NODE_PIDS=$(pgrep -f "node.*coze-studio" || echo "")
if [ -n "$NODE_PIDS" ]; then
echo "🎯 发现 Node.js 进程: $NODE_PIDS"
echo "$NODE_PIDS" | xargs kill -TERM 2>/dev/null || true
sleep 2
echo "$NODE_PIDS" | xargs kill -KILL 2>/dev/null || true
echo "✅ Node.js 进程已停止"
else
echo " 未发现运行中的 Node.js 进程"
fi
# 停止 Docker 容器
echo "🐳 停止 Docker 容器..."
cd docker
if docker compose version &> /dev/null; then
if docker compose ps -q | grep -q .; then
echo "🎯 正在停止 Docker 容器..."
docker compose down
echo "✅ Docker 容器已停止"
else
echo " 未发现运行中的 Docker 容器"
fi
else
if docker-compose ps -q | grep -q .; then
echo "🎯 正在停止 Docker 容器..."
docker-compose down
echo "✅ Docker 容器已停止"
else
echo " 未发现运行中的 Docker 容器"
fi
fi
cd ..
# 清理临时文件
echo "🧹 清理临时文件..."
find . -name "node_modules" -type d -prune -exec rm -rf {} + 2>/dev/null || true
find . -name ".next" -type d -prune -exec rm -rf {} + 2>/dev/null || true
find . -name "dist" -type d -prune -exec rm -rf {} + 2>/dev/null || true
find . -name ".turbo" -type d -prune -exec rm -rf {} + 2>/dev/null || true
echo "✅ 临时文件清理完成"
# 显示最终状态
echo ""
echo "📊 服务状态:"
echo "🌐 前端开发服务器: 已停止"
echo "🐳 Docker 容器: 已停止"
echo "🧹 临时文件: 已清理"
echo ""
echo "👋 Coze Studio 已完全关闭!"
echo ""
echo "💡 如果需要重新启动,请运行:"
echo " ./start.sh"