[fix:10]修改启动脚本中配置文件检测方式
This commit is contained in:
@@ -638,13 +638,12 @@ docker_custom_preinit() {
|
||||
# 检测用户配置文件目录是否存在 preinitdb.d 文件夹,如果存在,尝试执行目录中的初始化脚本
|
||||
if [ -d "/srv/conf/${APP_NAME}/preinitdb.d" ]; then
|
||||
# 检测数据存储目录是否存在已初始化标志文件;如果不存在,检索可执行脚本文件并进行初始化操作
|
||||
if [ ! -f "${APP_DATA_DIR}/.custom_preinit_flag" ]; then
|
||||
if [[ -n $(find "/srv/conf/${APP_NAME}/preinitdb.d/" -type f -regex ".*\.\(sh\)") ]] && \
|
||||
[[ ! -f "${APP_DATA_DIR}/.custom_preinit_flag" ]]; then
|
||||
LOG_I "Process custom pre-init scripts from /srv/conf/${APP_NAME}/preinitdb.d..."
|
||||
|
||||
# 检测目录权限,防止初始化失败
|
||||
ls "/srv/conf/${APP_NAME}/preinitdb.d/" > /dev/null
|
||||
|
||||
docker_process_init_files /srv/conf/${APP_NAME}/preinitdb.d/*
|
||||
# 检索所有可执行脚本,排序后执行
|
||||
find "/srv/conf/${APP_NAME}/preinitdb.d/" -type f -regex ".*\.\(sh\)" | sort | docker_process_init_files
|
||||
|
||||
touch ${APP_DATA_DIR}/.custom_preinit_flag
|
||||
echo "$(date '+%Y-%m-%d %H:%M:%S') : Init success." >> ${APP_DATA_DIR}/.custom_preinit_flag
|
||||
|
||||
@@ -48,7 +48,9 @@ docker_ensure_dir_and_configs() {
|
||||
|
||||
# 检测指定文件是否在配置文件存储目录存在,如果不存在则拷贝(新挂载数据卷、手动删除都会导致不存在)
|
||||
LOG_D "Check config files..."
|
||||
ensure_config_file_exist ${APP_DEF_DIR}/*
|
||||
if [[ ! -z "$(ls -A "$dir")" ]]; then
|
||||
ensure_config_file_exist "${APP_DEF_DIR}" $(ls -A "${APP_DEF_DIR}")
|
||||
fi
|
||||
}
|
||||
|
||||
_main() {
|
||||
|
||||
@@ -91,23 +91,27 @@ docker_process_init_files() {
|
||||
# 默认配置文件路径:/etc/${APP_NAME}
|
||||
# 目标配置文件路径:/srv/conf/${APP_NAME}
|
||||
# 参数:
|
||||
# $* - 文件及目录列表字符串,以" "分割
|
||||
# $1 - 基础路径
|
||||
# $* - 基础路径下的文件及目录列表,以" "分割
|
||||
# 例子:
|
||||
# ensure_config_file_exist /etc/${APP_NAME}/*
|
||||
# ensure_config_file_exist /etc/${APP_NAME} conf.d server.conf
|
||||
ensure_config_file_exist() {
|
||||
local f
|
||||
local -r base_path="${1:?paths is missing}"
|
||||
local f=""
|
||||
local dist=""
|
||||
|
||||
shift 1
|
||||
LOG_D "List to check: $@"
|
||||
while [ "$#" -gt 0 ]; do
|
||||
f="${1}"
|
||||
LOG_D "Process ${f}"
|
||||
if [ -d ${f} ]; then
|
||||
dist="$(echo ${f} | sed -e 's/\/etc/\/srv\/conf/g')"
|
||||
if [ -d "${f}" ]; then
|
||||
dist="$(echo ${base_path}/${f} | sed -e 's/\/etc/\/srv\/conf/g')"
|
||||
[ ! -d "${dist}" ] && LOG_I "Create directory: ${dist}" && mkdir -p "${dist}"
|
||||
[[ ! -z $(ls -A "$f") ]] && ensure_config_file_exist ${f}/*
|
||||
[[ ! -z $(ls -A "${f}") ]] && ensure_config_file_exist "${base_path}/${f}" $(ls -A "${base_path}/${f}")
|
||||
else
|
||||
dist="$(echo ${f} | sed -e 's/\/etc/\/srv\/conf/g')"
|
||||
[ ! -e "${dist}" ] && LOG_I "Copy: ${f} ===> ${dist}" && cp "${f}" "${dist}" && rm -rf "/srv/data/${APP_NAME}/.app_init_flag"
|
||||
dist="$(echo ${base_path}/${f} | sed -e 's/\/etc/\/srv\/conf/g')"
|
||||
[ ! -e "${dist}" ] && LOG_I "Copy: ${base_path}/${f} ===> ${dist}" && cp "${base_path}/${f}" "${dist}" && rm -rf "/srv/conf/${APP_NAME}/.app_init_flag"
|
||||
fi
|
||||
shift
|
||||
done
|
||||
|
||||
Reference in New Issue
Block a user