Files
gangyan/scripts/frontend-restart.sh

30 lines
1.2 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env bash
# 须用 bash 执行;若误用 sh/dash 会自动改用 bash 再跑一遍
[ -n "${BASH_VERSION:-}" ] || exec /usr/bin/env bash "$0" ${1+"$@"}
# 重启前端 vitenpm run dev按 chat_web_project 使用的端口释放(默认读 .env 中 VITE_GLOB_FRONT_PORT
# 日志gangyan/logs/frontend.log
set -u
source "$(cd "$(dirname "$0")" && pwd)/common-restart.sh"
LOG_FILE="$LOG_DIR/frontend.log"
FRONT_ENV="$GANGYAN_ROOT/chat_web_front/.env"
FRONT_PORT=3000
if [ -f "$FRONT_ENV" ]; then
_p=$(grep -E '^[[:space:]]*VITE_GLOB_FRONT_PORT=' "$FRONT_ENV" | head -1 | cut -d= -f2 | tr -d '\r"[:space:]')
[ -n "${_p:-}" ] && FRONT_PORT="$_p"
fi
log_tee "======== 停止前端(端口 $FRONT_PORT========"
for pid in $(lsof -ti :"$FRONT_PORT" -sTCP:LISTEN 2>/dev/null || true); do
kill -TERM "$pid" 2>/dev/null && log_tee "TERM pid=$pid" || true
done
sleep 2
for pid in $(lsof -ti :"$FRONT_PORT" -sTCP:LISTEN 2>/dev/null || true); do
kill -KILL "$pid" 2>/dev/null && log_tee "KILL pid=$pid" || true
done
log_tee "======== 启动 npm run dev ========"
cd "$GANGYAN_ROOT/chat_web_front"
nohup npm run dev >> "$LOG_FILE" 2>&1 &
log_tee "已后台启动PID=$! ,端口约 $FRONT_PORT ,日志: $LOG_FILE"