Files
shop-platform/docker/php/entrypoint.sh

59 lines
1.4 KiB
Bash
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.
#!/bin/bash
set -e
# 设置全局umask
umask 0002
echo "=== ThinkPHP Docker权限初始化 ==="
# 修复目录所有权和权限
fix_directory_permissions() {
local dir=$1
echo "修复目录权限: $dir"
# 确保目录存在
mkdir -p "$dir"
# 设置所有权
chown -R www-data:www-data "$dir"
# 设置权限
chmod -R 775 "$dir"
# 设置setgid权限
chmod g+s "$dir"
# 尝试设置ACL如果支持
if command -v setfacl >/dev/null 2>&1; then
setfacl -d -m u:www-data:rwx -m u:root:rwx "$dir" 2>/dev/null || true
setfacl -Rm u:www-data:rwx "$dir" 2>/dev/null || true
fi
echo "$dir 权限设置完成"
}
# 处理所有需要权限的目录
directories=("runtime" "upload")
for dir in "${directories[@]}"; do
fix_directory_permissions "/var/www/html/$dir"
done
# 验证权限
echo "=== 权限验证 ==="
echo "当前用户: $(whoami)"
echo "当前UID: $(id -u), GID: $(id -g)"
echo "当前umask: $(umask)"
# 测试写入权限
sudo -u www-data mkdir -p /var/www/html/runtime/test_dir 2>/dev/null && \
echo "✅ runtime目录新建子目录测试通过" || \
echo "❌ runtime目录新建子目录失败"
sudo -u www-data mkdir -p /var/www/html/upload/test_dir 2>/dev/null && \
echo "✅ upload目录新建子目录测试通过" || \
echo "❌ upload目录新建子目录失败"
echo "=== 启动应用 ==="
# 执行原有的启动命令
exec "$@"