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

56 lines
1.3 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

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.

#!/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}")
if not Logger.run_command("docker-compose build --no-cache ruoyi-redis", docker_dir):
Logger.error("Redis 镜像构建失败")
return False
Logger.info("Redis 镜像构建成功")
if not Logger.run_command("docker-compose up -d ruoyi-redis", docker_dir):
Logger.error("Redis 容器启动失败")
return False
Logger.info("Redis 容器启动成功")
Logger.info("Redis 初始化完成")
return True
except Exception as e:
Logger.error(f"Redis 初始化异常: {e}")
return False