From da36d3b31914e5e2a36795c00d0bc5323983e320 Mon Sep 17 00:00:00 2001 From: kuaifan Date: Wed, 24 Jun 2026 06:51:21 +0000 Subject: [PATCH] =?UTF-8?q?fix(cmd):=20=E4=BF=AE=E5=A4=8D=E5=AE=89?= =?UTF-8?q?=E8=A3=85=20nginx=20=E6=9C=AA=E8=87=AA=E5=8A=A8=E5=90=AF?= =?UTF-8?q?=E5=8A=A8=E3=80=81=E5=8D=B8=E8=BD=BD=E6=AE=8B=E7=95=99=E5=91=BD?= =?UTF-8?q?=E5=90=8D=E5=8D=B7=E3=80=81root=20=E6=9B=B4=E6=96=B0=E8=A2=AB?= =?UTF-8?q?=20git=20=E6=8B=A6=E6=88=AA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - install/update: 新增 wait_php_healthy,等 php 健康后兜底拉起 nginx, 规避 depends_on 时序竞态导致"显示完成却访问不到" - uninstall: down 增加 --volumes,清除 shared_data/redis_data 命名卷 - update: git 操作前加幂等 safe.directory 白名单,规避以 root 操作普通 用户克隆仓库时被 git 归属检查拦截 Co-Authored-By: Claude Opus 4.8 (1M context) --- cmd | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/cmd b/cmd index c6ccfa588..f12b7ffc9 100755 --- a/cmd +++ b/cmd @@ -274,6 +274,19 @@ docker_name() { echo `$COMPOSE ps | awk '{print $1}' | grep "\-$1\-"` } +# 等待 php 容器健康(最多约 90s) +wait_php_healthy() { + local name st wait=0 + name="$(docker_name php)" + [ -z "$name" ] && return 0 + while [ $wait -lt 90 ]; do + st="$(docker inspect -f '{{if .State.Health}}{{.State.Health.Status}}{{else}}{{.State.Status}}{{end}}' "$name" 2>/dev/null)" + { [ "$st" = "healthy" ] || [ "$st" = "running" ]; } && break + sleep 3 + wait=$((wait + 3)) + done +} + # 编译前端 web_build() { local type=$1 @@ -784,6 +797,10 @@ handle_install() { # 启动所有容器 $COMPOSE up -d --remove-orphans + # 兜底拉起 nginx(避免首启时序竞态) + wait_php_healthy + [ -z "$(docker_name nginx)" ] && $COMPOSE up -d --remove-orphans + success "$(msg '安装完成')" echo -e "$(msg '地址'): http://${GreenBG}127.0.0.1:$(env_get APP_PORT)${Font}" container_exec mariadb "sh /etc/mysql/repassword.sh" @@ -809,6 +826,9 @@ handle_update() { fi if [[ -z "$is_local" ]]; then + # 信任项目目录,避免 git 归属检查拦截 + git config --global --get-all safe.directory 2>/dev/null | grep -qxF "${WORK_DIR}" \ + || git config --global --add safe.directory "${WORK_DIR}" 2>/dev/null # 检查本地修改 if ! git diff --quiet || ! git diff --cached --quiet; then if [[ "$force_update" != "yes" ]]; then @@ -883,6 +903,10 @@ handle_update() { $COMPOSE down --remove-orphans exec_judge "$COMPOSE up -d" "$(msg '重启服务失败')" fi + + # 兜底拉起 nginx(避免首启时序竞态) + wait_php_healthy + [ -z "$(docker_name nginx)" ] && $COMPOSE up -d --remove-orphans env_set UPDATE_TIME "$(date +%s)" success "$(msg '更新完成')" @@ -912,8 +936,8 @@ handle_uninstall() { # 清理网络相关容器 remove_by_network - # 停止并删除容器 - $COMPOSE down --remove-orphans + # 停止并删除容器(含命名卷) + $COMPOSE down --remove-orphans --volumes # 重置调试模式 env_set APP_DEBUG "false"