test
This commit is contained in:
@@ -105,6 +105,7 @@ _check_fe_port_free() {
|
|||||||
local port="${FE_PORT_NUM[$name]}"
|
local port="${FE_PORT_NUM[$name]}"
|
||||||
local pids
|
local pids
|
||||||
|
|
||||||
|
info "检查 ${BOLD}$name${NC} 端口 $port ..."
|
||||||
pids="$(lsof -tiTCP:"$port" -sTCP:LISTEN 2>/dev/null || true)"
|
pids="$(lsof -tiTCP:"$port" -sTCP:LISTEN 2>/dev/null || true)"
|
||||||
if [[ -n "$pids" ]]; then
|
if [[ -n "$pids" ]]; then
|
||||||
error "$name 启动失败: 端口 $port 已被占用"
|
error "$name 启动失败: 端口 $port 已被占用"
|
||||||
@@ -112,6 +113,7 @@ _check_fe_port_free() {
|
|||||||
lsof -nP -iTCP:"$port" -sTCP:LISTEN 2>/dev/null || true
|
lsof -nP -iTCP:"$port" -sTCP:LISTEN 2>/dev/null || true
|
||||||
echo ""
|
echo ""
|
||||||
echo "请先停止占用进程,例如:"
|
echo "请先停止占用进程,例如:"
|
||||||
|
echo " ./deploy-test/stop-frontend.sh $name"
|
||||||
echo " lsof -ti :$port | xargs -r kill"
|
echo " lsof -ti :$port | xargs -r kill"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
@@ -126,12 +128,13 @@ _start_fe() {
|
|||||||
local env_prefix="${FE_ENV[$name]}"
|
local env_prefix="${FE_ENV[$name]}"
|
||||||
local pidfile="$PID_DIR/fe-${name}.pid"
|
local pidfile="$PID_DIR/fe-${name}.pid"
|
||||||
local logfile="$LOG_DIR/fe-${name}.log"
|
local logfile="$LOG_DIR/fe-${name}.log"
|
||||||
|
local port="${FE_PORT_NUM[$name]}"
|
||||||
|
|
||||||
_check_fe_port_free "$name" || return 1
|
_check_fe_port_free "$name" || return 1
|
||||||
|
|
||||||
# 已在运行
|
# 已在运行
|
||||||
if [[ -f "$pidfile" ]] && kill -0 "$(cat "$pidfile")" 2>/dev/null; then
|
if [[ -f "$pidfile" ]] && kill -0 "$(cat "$pidfile")" 2>/dev/null; then
|
||||||
warn "$name 已在运行 (PID=$(cat "$pidfile")),跳过"
|
warn "$name 已在运行 (端口=$port, PID=$(cat "$pidfile")),跳过"
|
||||||
if [[ "$name" == "pc" ]]; then
|
if [[ "$name" == "pc" ]]; then
|
||||||
warn " Vite 环境变量只在启动时读取;若仍请求旧地址,请执行: ./deploy-test/stop-frontend.sh pc && ./deploy-test/07-start-frontend.sh pc"
|
warn " Vite 环境变量只在启动时读取;若仍请求旧地址,请执行: ./deploy-test/stop-frontend.sh pc && ./deploy-test/07-start-frontend.sh pc"
|
||||||
pc_export_vite_backend_env
|
pc_export_vite_backend_env
|
||||||
@@ -142,23 +145,23 @@ _start_fe() {
|
|||||||
|
|
||||||
# 目录检查
|
# 目录检查
|
||||||
if [[ ! -d "$dir" ]]; then
|
if [[ ! -d "$dir" ]]; then
|
||||||
warn "$name 目录不存在 ($dir),跳过"
|
warn "$name 目录不存在 (端口=$port, 目录=$dir),跳过"
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# 依赖检查
|
# 依赖检查
|
||||||
if [[ ! -d "$dir/node_modules" ]]; then
|
if [[ ! -d "$dir/node_modules" ]]; then
|
||||||
warn "$name node_modules 不存在,请先执行: ./deploy-test/06-install-frontend.sh $name"
|
warn "$name node_modules 不存在 (端口=$port),请先执行: ./deploy-test/06-install-frontend.sh $name"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# 包管理器检查
|
# 包管理器检查
|
||||||
if ! command -v "$pm" &>/dev/null; then
|
if ! command -v "$pm" &>/dev/null; then
|
||||||
error "$name 需要 $pm,未安装"
|
error "$name 需要 $pm,未安装 (端口=$port)"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
info "启动 ${BOLD}$name${NC} ..."
|
info "启动 ${BOLD}$name${NC} (端口=$port) ..."
|
||||||
if [[ "$name" == "pc" ]]; then
|
if [[ "$name" == "pc" ]]; then
|
||||||
pc_ensure_wasm_assets
|
pc_ensure_wasm_assets
|
||||||
pc_export_vite_backend_env
|
pc_export_vite_backend_env
|
||||||
@@ -190,13 +193,13 @@ _start_fe() {
|
|||||||
|
|
||||||
sleep 2
|
sleep 2
|
||||||
if [[ -f "$pidfile" ]] && kill -0 "$(cat "$pidfile")" 2>/dev/null; then
|
if [[ -f "$pidfile" ]] && kill -0 "$(cat "$pidfile")" 2>/dev/null; then
|
||||||
success " ✓ $name (PID=$(cat "$pidfile")) ${FE_PORT[$name]} → $logfile"
|
success " ✓ $name (端口=$port, PID=$(cat "$pidfile")) ${FE_PORT[$name]} → $logfile"
|
||||||
if [[ "$name" == "pc" ]]; then
|
if [[ "$name" == "pc" ]]; then
|
||||||
pc_check_wasm_assets "${PC_BACKEND_ORIGIN}"
|
pc_check_wasm_assets "${PC_BACKEND_ORIGIN}"
|
||||||
info " PC 浏览器入口建议使用: ${PC_BACKEND_ORIGIN%/}/"
|
info " PC 浏览器入口建议使用: ${PC_BACKEND_ORIGIN%/}/"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
error " ✗ $name 启动失败,查看日志:"
|
error " ✗ $name 启动失败 (端口=$port),查看日志:"
|
||||||
tail -20 "$logfile" 2>/dev/null || true
|
tail -20 "$logfile" 2>/dev/null || true
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user