Files
ulthon_admin/source/stack/docker-dev-sync/source/docker/run.sh
augushong e5cbb48bcc fix(stack): 开发模式移除VOLUME消除runtime遮蔽,run.sh权限与su写法修复
- docker-dev/docker-dev-sync 删除 4 行 VOLUME:匿名卷会遮蔽整目录 bind mount 的宿主 runtime(已实证:宿主看不到容器日志)
- run.sh 统一四目录 777 + umask + 正确 su 写法(-s /bin/sh,www-data 为 nologin)
- serve/full/author 生产模式 VOLUME 保留作 docker run -v 兜底
2026-09-09 14:45:21 +00:00

79 lines
3.3 KiB
Bash
Raw 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
# 开发环境 umask:bind mount 下 Dockerfile 的权限处理被宿主目录覆盖,
# PHP 新建的子目录(如 runtime/cache/da/)默认 755 导致 www-data 无法写入。
# 设 000 让子进程(php-fpm worker / timer)创建的文件/目录全局可写。
umask 000
# 自动检测脚本所在目录(B-route 兼容:bind mount 下路径为 source/stack/<mode>/source/docker/)
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# ============================================
# run.sh - docker-dev-sync entrypoint
# ============================================
# 1. Syncs host code from /var/www/source to /var/www/html
# 2. Configures nginx and php-fpm
# 3. Starts background sync polling
# 4. Starts application services
# ============================================
# ---- Step 1: Initial code sync (foreground, blocking) ----
echo "[run] Checking source mount..."
if [ -d "/var/www/source" ] && [ "$(ls -A /var/www/source 2>/dev/null)" ]; then
echo "[run] Source directory mounted, performing initial sync..."
/bin/bash "$SCRIPT_DIR/sync.sh" init
echo "[run] Initial sync finished."
# Start background polling
/bin/bash "$SCRIPT_DIR/sync.sh" watch &
SYNC_PID=$!
echo "[run] Background sync polling started (PID: ${SYNC_PID}, interval: ${SYNC_INTERVAL:-3}s)."
else
echo "[run] WARNING: /var/www/source is not mounted or empty."
echo "[run] Running with build-time files only (no live sync)."
fi
# ---- Step 2: Configure services ----
# Copy nginx config
cp "$SCRIPT_DIR/nginx.conf" /etc/nginx/sites-available/default
ln -sf /etc/nginx/sites-available/default /etc/nginx/sites-enabled/default
# Copy php config files
cp "$SCRIPT_DIR/zz-phprun.ini" /usr/local/etc/php/conf.d
cp "$SCRIPT_DIR/zz-phpfpm.conf" /usr/local/php-fpm.d
# Dev mode: override production PHP config (Opcache, error display, Xdebug)
cp "$SCRIPT_DIR/zzz-dev.ini" /usr/local/etc/php/conf.d
cp "$SCRIPT_DIR/zzz-xdebug.ini" /usr/local/etc/php/conf.d
# ---- Step 3: Set directory permissions ----
# bind mount 覆盖 Dockerfile 的 mkdir/chmod,必须在启动脚本中重建
# 预创建 ThinkPHP 运行时关键子目录,避免首次写入时 No such file or directory
mkdir -p /var/www/html/runtime/{cache,log,temp,session,nginx} && chmod -R 777 /var/www/html/runtime
mkdir -p /var/www/html/public/storage && chmod -R 777 /var/www/html/public/storage
mkdir -p /var/www/html/public/build && chmod -R 777 /var/www/html/public/build
mkdir -p /var/www/html/storage && chmod -R 777 /var/www/html/storage
mkdir -p /var/www/html/memoryspace && chown -R www-data:www-data /var/www/html/memoryspace
# 复制 nginx_log 分析的 log_format 配置到 nginx http 块(conf.d 自动 include)
cp "$SCRIPT_DIR/nginx-log-format.conf" /etc/nginx/conf.d/
# 创建 nginx access_log 目录(必须在 service nginx start 之前)
mkdir -p /var/www/html/runtime/nginx && chmod 777 /var/www/html/runtime/nginx
# ---- Step 4: Output parameters and start services ----
echo "参数为:$@"
if [ "$1" = "server" ] || [ "$1" = "" ]; then
# Run timer (background, as www-data; nologin account requires -s /bin/sh with username last)
su -s /bin/sh -c "nohup php /var/www/html/think timer --local --quiet &" www-data
# Run nginx
service nginx start
# Run php-fpm (foreground, keeps container alive)
php-fpm
else
php "/var/www/html/""$@"
fi