From 546e5f4b3dbc0a882fbcb777b000bc98ed9d0f22 Mon Sep 17 00:00:00 2001 From: chenhang Date: Fri, 12 Jun 2026 18:24:08 +0800 Subject: [PATCH] chore(githooks): rename hooks dir to .githooks and stop old next processes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Move repository-managed git hooks from `git_hooks/` to `.githooks/` to follow the conventional hidden-directory naming, and add a graceful shutdown step in `post-receive` that terminates any running `next start` / `next-server` processes (SIGTERM → wait 2s → SIGKILL → wait 1s) before relaunching, avoiding EADDRINUSE port conflicts so the freshly built code actually takes effect. README updated to reference the new path. --- {git_hooks => .githooks}/post-receive | 15 +++++++++++++++ README.md | 6 +++--- 2 files changed, 18 insertions(+), 3 deletions(-) rename {git_hooks => .githooks}/post-receive (74%) diff --git a/git_hooks/post-receive b/.githooks/post-receive similarity index 74% rename from git_hooks/post-receive rename to .githooks/post-receive index 48e0f0a6..f974a666 100755 --- a/git_hooks/post-receive +++ b/.githooks/post-receive @@ -37,6 +37,21 @@ if [ $BUILD_EXIT -ne 0 ]; then exit $BUILD_EXIT fi +# build 成功 → **先**关闭旧 next 进程(**避**免端口 EADDRINUSE 冲突,新代码**能**生效) +echo "=== stop existing next @ $(date -u +%Y-%m-%dT%H:%M:%SZ) ===" >> "$LOG_FILE" +# 1) **优**雅**关**闭(SIGTERM)—— 旧进程**自**己 drain 现有请求 +pkill -f "next start" 2>/dev/null +pkill -f "next-server" 2>/dev/null +# 2) 等 2s 让**优**雅**关**闭**完**成 +sleep 2 +# 3) 强杀(SIGKILL)—— **还**在**的**话 +pkill -9 -f "next start" 2>/dev/null +pkill -9 -f "next-server" 2>/dev/null +# 4) **最**后等 1s 确**保**端口**完**全释放 +sleep 1 +echo "=== stop DONE @ $(date -u +%Y-%m-%dT%H:%M:%SZ) ===" >> "$LOG_FILE" +echo "" >> "$LOG_FILE" + # pnpm run start → **后台**跑(nohup ... &),long-running 进程 # 输出**丢**(> /dev/null 2>&1)—— 真实 next 日志要看 next 自身 stdout/stderr,**不**在本任务范围 echo "=== start LAUNCH @ $(date -u +%Y-%m-%dT%H:%M:%SZ) ===" >> "$LOG_FILE" diff --git a/README.md b/README.md index 11428835..a8418526 100644 --- a/README.md +++ b/README.md @@ -22,10 +22,10 @@ This project uses [`next/font`](https://nextjs.org/docs/app/building-your-applic ## Git Hooks -项目使用 `git_hooks/` 目录存放**仓库内**的 git hooks(**不**在 `.git/hooks/`)。**clone 后需手动启用**: +项目使用 `.githooks/` 目录存放**仓库内**的 git hooks(**不**在 `.git/hooks/`)。**clone 后需手动启用**: ```bash -git config core.hooksPath git_hooks +git config core.hooksPath .githooks ``` ### 启用的 Hook @@ -38,7 +38,7 @@ git config core.hooksPath git_hooks **注意事项**: -- 本仓库的 `git_hooks/post-receive` **不**会**自动**生效 —— 必须在每个工作副本上跑一次上面的 `git config` 命令 +- 本仓库的 `.githooks/post-receive` **不**会**自动**生效 —— 必须在每个工作副本上跑一次上面的 `git config` 命令 - `core.hooksPath` 是**本地** git config(写入 `.git/config`),**不**随仓库提交 - `post-receive` 在**接收端**触发 —— 即 push 目标机器(生产 / 测试服务器)的 hook,不是本地开发机的