imetting/start.sh

212 lines
5.2 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#!/bin/bash
# iMeeting Docker 快速启动脚本
# 使用方法: ./start.sh [选项]
set -e
# 颜色定义
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# 打印带颜色的消息
print_info() {
echo -e "${BLUE}[INFO]${NC} $1"
}
print_success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
# 打印banner
print_banner() {
echo -e "${BLUE}"
cat << "EOF"
_ __ __ _ _
(_) \/ | ___ ___| |_(_)_ __ __ _
| | |\/| |/ _ \/ _ \ __| | '_ \ / _` |
| | | | | __/ __/ |_| | | | | (_| |
|_|_| |_|\___|\___|\__|_|_| |_|\__, |
|___/
Docker Deployment Script
EOF
echo -e "${NC}"
}
# 检查依赖
check_dependencies() {
print_info "检查系统依赖..."
if ! command -v docker &> /dev/null; then
print_error "未安装 Docker请先安装 Docker"
exit 1
fi
if ! command -v docker-compose &> /dev/null && ! docker compose version &> /dev/null; then
print_error "未安装 Docker Compose请先安装 Docker Compose"
exit 1
fi
print_success "系统依赖检查通过"
}
# 检查环境变量文件
check_env_file() {
print_info "检查环境变量配置..."
if [ ! -f .env ]; then
print_warning ".env 文件不存在,从模板创建..."
cp .env.example .env
print_warning "请编辑 .env 文件配置必要的参数七牛云、LLM API等"
print_warning "按任意键继续,或 Ctrl+C 退出..."
read -n 1 -s
else
print_success "环境变量文件已存在"
fi
}
# 检查并创建后端环境变量文件# 创建必要的目录
create_directories() {
print_info "创建必要的目录..."
# MySQL和Nginx配置目录
mkdir -p mysql/conf.d
# 数据持久化目录
mkdir -p data/mysql
mkdir -p data/redis
mkdir -p data/uploads
mkdir -p data/logs/backend
mkdir -p data/logs/frontend
# 后端配置和备份目录
mkdir -p backend/config
mkdir -p backups
print_success "目录创建完成"
}
# 启动服务
start_services() {
print_info "启动 Docker 服务..."
# 使用 docker compose 或 docker-compose
if docker compose version &> /dev/null; then
COMPOSE_CMD="docker compose"
else
COMPOSE_CMD="docker-compose"
fi
$COMPOSE_CMD up -d
print_success "服务启动命令已执行"
}
# 等待服务健康
wait_for_health() {
print_info "等待服务启动..."
local max_wait=120
local waited=0
while [ $waited -lt $max_wait ]; do
if docker compose version &> /dev/null; then
COMPOSE_CMD="docker compose"
else
COMPOSE_CMD="docker-compose"
fi
local healthy_count=$($COMPOSE_CMD ps --format json 2>/dev/null | grep -c '"Health":"healthy"' || echo "0")
local total_count=4 # mysql, redis, backend, frontend
if [ "$healthy_count" -eq "$total_count" ]; then
print_success "所有服务已就绪"
return 0
fi
echo -ne "\r等待中... (${waited}s/${max_wait}s) 健康: ${healthy_count}/${total_count}"
sleep 5
waited=$((waited + 5))
done
echo ""
print_warning "服务启动超时,请手动检查状态: docker-compose ps"
return 1
}
# 显示服务状态
show_status() {
print_info "服务状态:"
if docker compose version &> /dev/null; then
docker compose ps
else
docker-compose ps
fi
}
# 显示访问信息
show_access_info() {
echo ""
print_success "==================================="
print_success " iMeeting 部署完成!"
print_success "==================================="
echo ""
echo -e "${GREEN}访问地址:${NC}"
echo -e " HTTP访问: ${BLUE}http://localhost${NC}"
echo -e " 或通过服务器IP访问${BLUE}http://服务器IP${NC}"
echo -e " API文档: ${BLUE}http://localhost/docs${NC}"
echo ""
echo -e "${YELLOW}域名访问HTTPS:${NC}"
echo -e " 需要在接入服务器配置Nginx代理"
echo -e " 参考文档: ${BLUE}GATEWAY_NGINX_CONFIG.md${NC}"
echo ""
echo -e "${YELLOW}数据目录:${NC}"
echo -e " 数据持久化: ${BLUE}./data/${NC}"
echo -e " - MySQL: ${BLUE}./data/mysql/${NC}"
echo -e " - Redis: ${BLUE}./data/redis/${NC}"
echo -e " - 上传文件: ${BLUE}./data/uploads/${NC}"
echo -e " - 日志: ${BLUE}./data/logs/${NC}"
echo ""
echo -e "${YELLOW}常用命令:${NC}"
echo -e " 管理菜单: ${BLUE}./manage.sh${NC}"
echo -e " 查看日志: ${BLUE}docker-compose logs -f${NC}"
echo -e " 停止服务: ${BLUE}./stop.sh${NC}"
echo -e " 重启服务: ${BLUE}docker-compose restart${NC}"
echo -e " 查看状态: ${BLUE}docker-compose ps${NC}"
echo ""
echo -e "${YELLOW}更多信息请查看: ${BLUE}DOCKER_DEPLOYMENT.md${NC}"
echo ""
}
# 主函数
main() {
print_banner
check_dependencies
check_env_file
create_directories
start_services
echo ""
wait_for_health
echo ""
show_status
show_access_info
}
# 执行主函数
main "$@"