chore(githooks): rename hooks dir to .githooks and stop old next processes
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.
This commit is contained in:
@@ -37,6 +37,21 @@ if [ $BUILD_EXIT -ne 0 ]; then
|
|||||||
exit $BUILD_EXIT
|
exit $BUILD_EXIT
|
||||||
fi
|
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 进程
|
# pnpm run start → **后台**跑(nohup ... &),long-running 进程
|
||||||
# 输出**丢**(> /dev/null 2>&1)—— 真实 next 日志要看 next 自身 stdout/stderr,**不**在本任务范围
|
# 输出**丢**(> /dev/null 2>&1)—— 真实 next 日志要看 next 自身 stdout/stderr,**不**在本任务范围
|
||||||
echo "=== start LAUNCH @ $(date -u +%Y-%m-%dT%H:%M:%SZ) ===" >> "$LOG_FILE"
|
echo "=== start LAUNCH @ $(date -u +%Y-%m-%dT%H:%M:%SZ) ===" >> "$LOG_FILE"
|
||||||
@@ -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(**不**在 `.git/hooks/`)。**clone 后需手动启用**:
|
项目使用 `.githooks/` 目录存放**仓库内**的 git hooks(**不**在 `.git/hooks/`)。**clone 后需手动启用**:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
git config core.hooksPath git_hooks
|
git config core.hooksPath .githooks
|
||||||
```
|
```
|
||||||
|
|
||||||
### 启用的 Hook
|
### 启用的 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`),**不**随仓库提交
|
- `core.hooksPath` 是**本地** git config(写入 `.git/config`),**不**随仓库提交
|
||||||
- `post-receive` 在**接收端**触发 —— 即 push 目标机器(生产 / 测试服务器)的 hook,不是本地开发机的
|
- `post-receive` 在**接收端**触发 —— 即 push 目标机器(生产 / 测试服务器)的 hook,不是本地开发机的
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user