refactor: consolidate directory creation and permission settings into init-directories.sh

This commit is contained in:
zhao
2025-09-01 14:18:40 +08:00
parent c5c908b97b
commit 95af591ea2
6 changed files with 40 additions and 14 deletions

View File

@@ -43,7 +43,7 @@ ENV CRM_VERSION=${CRM_VERSION}
RUN echo "CRM_VERSION value during build: ${CRM_VERSION}"
RUN echo -n "${CRM_VERSION}" > /tmp/CRM_VERSION
VOLUME [ "/opt/cordys/data", "/opt/cordys/logs", "/opt/cordys/conf" ]
VOLUME [ "/opt/cordys" ]
RUN chmod 777 /shells/*.sh
RUN chmod -R 777 /opt/cordys

View File

@@ -0,0 +1,35 @@
#!/bin/bash
set -e
# 日志函数
log() {
echo "[$(date +'%Y-%m-%d %H:%M:%S')] $1"
}
# 需要确保存在的目录
DIRS=(
"/opt/cordys/data/mysql"
"/opt/cordys/conf/mysql"
"/opt/cordys/logs/cordys-crm"
"/opt/cordys/data/files"
"/opt/cordys/data/redis"
"/opt/cordys/conf/redis"
)
log "开始检查并创建必要目录..."
for d in "${DIRS[@]}"; do
if [ ! -d "$d" ]; then
log "创建目录: $d"
mkdir -p "$d"
else
log "目录已存在: $d"
fi
done
# 仅在目录存在时再设置权限
if [ -d "/opt/cordys" ]; then
log "设置目录权限: /opt/cordys"
chmod -R 777 /opt/cordys
fi
log "目录初始化完成。"

View File

@@ -43,7 +43,7 @@ get_property() {
# 主函数
main() {
log_info "开始启动 Cordys CRM 环境..."
chmod -R 777 /opt/cordys
sh /shells/init-directories.sh
# 检查MySQL配置并启动
mysqlEmbeddedEnabled=$(get_property "mysql.embedded.enabled")

View File

@@ -1,9 +1,6 @@
#!/bin/sh
mkdir -p /opt/cordys/logs/cordys-crm
mkdir -p /opt/cordys/data/files
chmod -R 777 /opt/cordys
sh /shells/init-directories.sh
export JAVA_CLASSPATH=/app:/app/lib/*
export JAVA_MAIN_CLASS=cn.cordys.Application

View File

@@ -1,9 +1,7 @@
#!/bin/sh
sh /shells/init-directories.sh
cp -rf /opt/cordys/conf/mysql/my.cnf /etc/my.cnf.d/mariadb-server.cnf
mkdir -p /opt/cordys/data/mysql
mkdir -p /opt/cordys/conf/mysql
chmod -R 777 /opt/cordys
chmod 644 /etc/mysql/conf.d/my.cnf

View File

@@ -6,11 +6,7 @@ log() {
echo "[$(date +'%Y-%m-%d %H:%M:%S')] $1"
}
# 创建必要目录
log "创建 Redis 数据目录..."
mkdir -p /opt/cordys/data/redis
mkdir -p /opt/cordys/conf/redis
chmod -R 777 /opt/cordys
sh /shells/init-directories.sh
# 检查 Redis 密码
if [ -z "${REDIS_PASSWORD}" ]; then