a-cloud-all/.devops/scripts/init/redis.py

56 lines
1.3 KiB
Python
Raw Permalink Normal View History

2026-01-10 15:15:45 +08:00
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Redis 初始化模块
"""
import subprocess
from pathlib import Path
import sys
# 添加父目录到路径
sys.path.insert(0, str(Path(__file__).parent.parent))
from log import Logger
def init_redis(project_root):
"""
初始化 Redis
参数
project_root: 项目根目录
返回
bool: 成功返回 True失败返回 False
"""
try:
project_root = Path(project_root).resolve()
Logger.separator()
Logger.info("开始初始化 Redis")
Logger.separator()
Logger.info(f"项目根目录: {project_root}")
docker_dir = project_root / "docker"
# 构建并启动 Redis 容器
Logger.info(f"执行目录: {docker_dir}")
2026-01-10 15:21:06 +08:00
if not Logger.run_command("docker-compose build --no-cache ruoyi-redis", docker_dir):
2026-01-10 15:15:45 +08:00
Logger.error("Redis 镜像构建失败")
return False
Logger.info("Redis 镜像构建成功")
2026-01-10 15:21:06 +08:00
if not Logger.run_command("docker-compose up -d ruoyi-redis", docker_dir):
2026-01-10 15:15:45 +08:00
Logger.error("Redis 容器启动失败")
return False
Logger.info("Redis 容器启动成功")
Logger.info("Redis 初始化完成")
return True
except Exception as e:
Logger.error(f"Redis 初始化异常: {e}")
return False