添加基础设施服务启动等待时间

- MySQL 等待 30 秒初始化
- Redis 等待 10 秒
- Nacos 等待 20 秒(确保 MySQL 就绪)
- 解决 Nacos 无法连接 MySQL 的问题
This commit is contained in:
孙小云 2026-01-09 18:36:16 +08:00
parent bae9bdd9a0
commit ddf030a178
2 changed files with 18 additions and 9 deletions

View File

@ -217,11 +217,14 @@ infrastructure:
- cp sql/ry_20250523.sql docker/mysql/db/
- cp sql/ry_config_20250902.sql docker/mysql/db/
deployed_flag: .devops/.deployed_mysql
wait_time: 30 # MySQL 需要更长时间初始化
- name: ruoyi-redis
docker_service: ruoyi-redis
deployed_flag: .devops/.deployed_redis
wait_time: 10 # Redis 启动较快
- name: ruoyi-nacos
docker_service: ruoyi-nacos
deployed_flag: .devops/.deployed_nacos
wait_time: 20 # Nacos 需要等待 MySQL 就绪

View File

@ -322,38 +322,44 @@ class Deployer:
return True
repo_path = self.runtime_path / 'a-cloud-all'
for infra in self.config['infrastructure']:
name = infra['name']
deployed_flag = repo_path / infra['deployed_flag']
# 检查是否已部署
if deployed_flag.exists():
self.logger.info(f"基础设施 {name} 已部署,跳过")
continue
self.logger.info(f"部署基础设施: {name}")
# 执行预部署命令
if 'pre_deploy_commands' in infra:
for cmd in infra['pre_deploy_commands']:
if not self.run_command(cmd, cwd=repo_path):
self.logger.error(f"预部署命令失败: {cmd}")
return False
# 部署服务
docker_service = infra['docker_service']
docker_dir = repo_path / 'docker'
cmd = f"docker-compose build --no-cache {docker_service} && docker-compose up -d {docker_service}"
if not self.run_command(cmd, cwd=docker_dir, timeout=1800):
self.logger.error(f"部署失败: {name}")
return False
# 等待服务启动(特别是 MySQL 和 Redis
wait_time = infra.get('wait_time', 10)
self.logger.info(f"等待 {name} 启动完成 ({wait_time} 秒)...")
import time
time.sleep(wait_time)
# 创建部署标记
deployed_flag.parent.mkdir(parents=True, exist_ok=True)
deployed_flag.touch()
self.logger.info(f"基础设施部署完成: {name}")
return True