-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart-dev.sh
More file actions
executable file
·51 lines (41 loc) · 1.2 KB
/
Copy pathstart-dev.sh
File metadata and controls
executable file
·51 lines (41 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env bash
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "$0")" && pwd)"
BACKEND_PID=""
WEBSITE_PID=""
cleanup() {
local exit_code=$?
if [[ -n "${BACKEND_PID}" ]] && kill -0 "${BACKEND_PID}" 2>/dev/null; then
kill "${BACKEND_PID}" 2>/dev/null || true
fi
if [[ -n "${WEBSITE_PID}" ]] && kill -0 "${WEBSITE_PID}" 2>/dev/null; then
kill "${WEBSITE_PID}" 2>/dev/null || true
fi
wait 2>/dev/null || true
exit "${exit_code}"
}
trap cleanup INT TERM EXIT
cd "${ROOT_DIR}/backend"
pnpm run dev &
BACKEND_PID=$!
cd "${ROOT_DIR}/website"
pnpm run dev &
WEBSITE_PID=$!
# 变更说明:
# - macOS 默认 /bin/bash 常见为 3.2,不支持 `wait -n`。
# - 这里先尝试 `wait -n`,失败则回退到兼容轮询逻辑,保证脚本在不同 Bash 版本都可用。
if help wait 2>/dev/null | rg -q -- '-n'; then
wait -n "${BACKEND_PID}" "${WEBSITE_PID}"
else
# 兼容模式:每秒检查一次两个子进程是否仍在运行。
# 只要任意一个进程退出,就结束等待并进入 cleanup 流程。
while true; do
if ! kill -0 "${BACKEND_PID}" 2>/dev/null; then
break
fi
if ! kill -0 "${WEBSITE_PID}" 2>/dev/null; then
break
fi
sleep 1
done
fi