#!/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 "📋 检查依赖..." # 检查 Docker if ! command -v docker &> /dev/null; then echo "❌ Docker 未安装,请先安装 Docker" exit 1 fi # 检查 Docker Compose if ! command -v docker-compose &> /dev/null && ! docker compose version &> /dev/null; then echo "❌ Docker Compose 未安装,请先安装 Docker Compose" exit 1 fi # 检查 Rush if ! command -v rush &> /dev/null; then echo "❌ Rush 未安装,请先安装 Rush" echo "安装命令: npm install -g @microsoft/rush" exit 1 fi echo "✅ 依赖检查完成" # 启动后端服务 echo "🔧 启动后端服务..." cd docker # 检查 .env 文件 if [ ! -f .env ]; then if [ -f .env.example ]; then echo "📄 创建 .env 文件..." cp .env.example .env echo "⚠️ 请根据需要编辑 .env 文件" else echo "⚠️ 未找到 .env.example 文件" fi fi # 启动 Docker 服务 echo "🐳 启动 Docker 容器..." if docker compose version &> /dev/null; then docker compose up -d else docker-compose up -d fi cd .. # 等待后端服务启动 echo "⏳ 等待后端服务启动..." sleep 10 # 安装前端依赖 echo "📦 安装前端依赖..." cd frontend rush update echo "🎨 启动前端开发服务器..." cd apps/coze-studio # 增加文件监控限制(解决 ENOSPC 错误) echo "🔧 配置文件监控限制..." if [[ "$OSTYPE" == "linux-gnu"* ]]; then sudo sysctl -w fs.inotify.max_user_watches=524288 2>/dev/null || true fi # 启动前端开发服务器 PORT=3001 rushx dev & FRONTEND_PID=$! echo "🎉 Coze Studio 启动完成!" echo "" echo "📍 前端地址: http://localhost:3001" echo "📍 API 地址: http://localhost:8888" echo "📍 文档地址: http://localhost:8888/docs" echo "" echo "🔍 查看日志:" echo " 后端日志: cd docker && docker compose logs -f" echo " 前端日志: cd frontend/apps/coze-studio && rushx dev" echo "" echo "🛑 停止服务:" echo " 停止所有服务: cd docker && docker compose down" echo " 停止前端: kill $FRONTEND_PID" # 保持脚本运行 wait $FRONTEND_PID