fix: 修复 standalone 模式启动路径问题
Some checks failed
CI / lint (push) Has been cancelled
CI / build (push) Has been cancelled

This commit is contained in:
2026-02-27 13:36:52 +08:00
parent c85bf31d99
commit 8a369a6535

51
run.sh
View File

@@ -33,8 +33,12 @@ prepare_standalone() {
start_server() {
if [ -f ".next/standalone/server.js" ]; then
NODE_ENV=production PORT=2333 nohup node .next/standalone/server.js > "$LOG_FILE" 2>&1 &
# Standalone 模式:从 standalone 目录启动服务器
cd .next/standalone
NODE_ENV=production PORT=2333 nohup node server.js > "../../$LOG_FILE" 2>&1 &
cd ../..
else
# 非 standalone 模式:使用 pnpm start
NODE_ENV=production nohup $PM run start > "$LOG_FILE" 2>&1 &
fi
}
@@ -64,36 +68,48 @@ function do_stop() {
function do_start() {
if [ -f "$PID_FILE" ] && kill -0 $(cat "$PID_FILE") 2>/dev/null; then
printf "${YELLOW}应用已经在运行中 (PID: $(cat $PID_FILE))${NC}\n"
printf "${YELLOW}App already running (PID: $(cat $PID_FILE))${NC}\n"
return 0
fi
PORT_PID=$(get_port_pids)
if [ -n "$PORT_PID" ]; then
printf "${YELLOW}?? 2333 ??????????????...${NC}\n"
printf "${YELLOW}Port 2333 is in use, trying to stop old process...${NC}\n"
do_stop
sleep 1
PORT_PID=$(get_port_pids)
if [ -n "$PORT_PID" ]; then
printf "${RED}??: ?? 2333 ?????????????????${NC}\n"
printf "${RED}Error: port 2333 still in use after auto-stop${NC}\n"
return 1
fi
fi
printf "${GREEN}?? $PM ?? STARK Todo List (production)...${NC}\n"
# 抑制安装输出,保持界面整? $PM install > /dev/null 2>&1
printf "${GREEN}Starting STARK Todo List (production) with $PM...${NC}\n"
NEED_BUILD=0
if [ ! -f ".next/BUILD_ID" ] && [ ! -f ".next/standalone/server.js" ]; then
NEED_BUILD=1
fi
if [ "$FORCE_BUILD" = "1" ] || [ "$2" = "build" ]; then
NEED_BUILD=1
fi
if [ "$NEED_BUILD" -eq 1 ]; then
$PM install > /dev/null 2>&1
$PM run build > /dev/null 2>&1
prepare_standalone
else
printf "${BLUE}Build artifacts found, skipping build. Force rebuild: FORCE_BUILD=1 bash run.sh start or bash run.sh start build${NC}\n"
fi
start_server
echo $! > "$PID_FILE"
sleep 2
if kill -0 $(cat "$PID_FILE") 2>/dev/null; then
printf "${GREEN}启动成功!访? http://localhost:2333${NC}\n"
printf "${GREEN}Started: http://localhost:2333${NC}\n"
else
printf "${RED}启动失败,请查看 $LOG_FILE${NC}\n"
printf "${RED}Start failed, check $LOG_FILE${NC}\n"
rm -f "$PID_FILE"
fi
}
@@ -119,33 +135,34 @@ case "$1" in
do_stop
;;
restart)
printf "${BLUE}正在执行彻底重启...${NC}\n"
printf "${BLUE}Restarting...${NC}\n"
do_stop
sleep 1
rm -rf .next
do_start
;;
logs)
[ -f "$LOG_FILE" ] && tail -f "$LOG_FILE" || printf "${RED}日志文件不存?{NC}\n"
[ -f "$LOG_FILE" ] && tail -f "$LOG_FILE" || printf "${RED}Log file not found${NC}\n"
;;
status)
if [ -n "$(get_port_pids)" ]; then
printf "${GREEN}应用正在运行${NC}\n"
printf "${GREEN}App is running${NC}\n"
(command -v lsof >/dev/null 2>&1 && lsof -i:2333) || (command -v ss >/dev/null 2>&1 && ss -ltnp 'sport = :2333') || (command -v netstat >/dev/null 2>&1 && netstat -ltnp) || true
else
printf "${RED}应用未运?{NC}\n"
printf "${RED}App is not running${NC}\n"
fi
;;
clean)
printf "${BLUE}清理缓存和日?..${NC}\n"
printf "${BLUE}Cleaning cache and logs...${NC}\n"
rm -rf .next "$LOG_FILE" "$PID_FILE"
printf "${GREEN}清理完成${NC}\n"
printf "${GREEN}Clean complete${NC}\n"
;;
*)
printf "${BLUE}STARK Todo List 本地管理脚本${NC}\n"
echo "用法: $0 [start|stop|restart|logs|status|clean]"
printf "${BLUE}STARK Todo List management script${NC}\n"
echo "Usage: $0 [start|stop|restart|logs|status|clean]"
exit 1
;;
esac
esac