Files
endial da723fed20
ci/woodpecker/push/woodpecker Pipeline was successful
feat: optimize nginx.conf and setup.sh for dynamic user ID support
- Increase worker connections to 4096 and enable multi_accept
- Add security headers for enhanced protection
- Improve gzip compression settings
- Add dynamic permission handling in setup.sh for runtime user ID changes
- Increase file descriptor limits to 65535
- Optimize timeout and buffer settings
- Fix health check configuration in Dockerfile
2026-01-26 14:13:54 +08:00

46 lines
1.7 KiB
Bash
Executable File

#!/bin/bash
# Ver: 1.3 by Endial Fang (endial@126.com)
#
# 应用环境及依赖文件设置脚本;当前脚本以‘root’用户执行
# 设置 shell 执行参数,可使用'-'(打开)'+'(关闭)控制。常用:
# -e: 命令执行错误则报错(errexit); -u: 变量未定义则报错(nounset); -x: 打印实际待执行的命令行; -o pipefail: 设置管道中命令遇到失败则报错
set -euo pipefail
. /usr/local/lib/libcommon.sh # 加载通用函数库
. /usr/local/lib/libfs.sh # 加载文件操作函数库
. /usr/local/lib/libos.sh # 加载系统管理函数库
. /usr/local/bin/environment.sh # 设置环境变量
. /usr/local/bin/common.sh # 应用专用函数库
info "** Processing setup.sh **"
APP_DIRS=(/var/log/${APP_NAME} /var/run/${APP_NAME} /var/cache/${APP_NAME} ${APP_HOME})
APP_DIRS+=(${APP_HOME}/conf ${APP_HOME}/data ${APP_HOME}/cert ${APP_HOME}/log)
info "Ensure directory exists: ${APP_DIRS[@]}"
for dir in ${APP_DIRS[@]}; do
ensure_dir_exists ${dir}
done
# 动态权限处理
current_uid=$(id -u)
current_gid=$(id -g)
# 确保当前用户对必要目录有访问权限
for dir in ${APP_DIRS[@]}; do
if [ -d "$dir" ]; then
chown $current_uid:$current_gid $dir
fi
done
# 检测指定文件是否在配置文件存储目录存在,如果不存在则拷贝(新挂载数据卷、手动删除都会导致不存在)
info "Check config files in: ${APP_CONF_DIR}"
if [[ -z "$(ls -A "${APP_CONF_DIR}")" ]]; then
app_ensure_config_file_exist "${APP_CONF_DIR}" "${APP_DEF_DIR}" $(ls -A "${APP_DEF_DIR}")
fi
# 解决使用non-root后,[emerg] open() "/dev/stdout" failed (13: Permission denied)
debug "Change permissions of stdout/stderr to 0662"
chmod 0662 /dev/stdout /dev/stderr