fix: 修复 standalone 模式启动路径问题
This commit is contained in:
55
run.sh
55
run.sh
@@ -33,8 +33,12 @@ prepare_standalone() {
|
|||||||
|
|
||||||
start_server() {
|
start_server() {
|
||||||
if [ -f ".next/standalone/server.js" ]; then
|
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
|
else
|
||||||
|
# 非 standalone 模式:使用 pnpm start
|
||||||
NODE_ENV=production nohup $PM run start > "$LOG_FILE" 2>&1 &
|
NODE_ENV=production nohup $PM run start > "$LOG_FILE" 2>&1 &
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
@@ -64,36 +68,48 @@ function do_stop() {
|
|||||||
|
|
||||||
function do_start() {
|
function do_start() {
|
||||||
if [ -f "$PID_FILE" ] && kill -0 $(cat "$PID_FILE") 2>/dev/null; then
|
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
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
PORT_PID=$(get_port_pids)
|
PORT_PID=$(get_port_pids)
|
||||||
if [ -n "$PORT_PID" ]; then
|
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
|
do_stop
|
||||||
sleep 1
|
sleep 1
|
||||||
PORT_PID=$(get_port_pids)
|
PORT_PID=$(get_port_pids)
|
||||||
if [ -n "$PORT_PID" ]; then
|
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
|
return 1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
printf "${GREEN}?? $PM ?? STARK Todo List (production)...${NC}\n"
|
printf "${GREEN}Starting STARK Todo List (production) with $PM...${NC}\n"
|
||||||
# 抑制安装输出,保持界面整? $PM install > /dev/null 2>&1
|
|
||||||
|
|
||||||
$PM run build > /dev/null 2>&1
|
NEED_BUILD=0
|
||||||
prepare_standalone
|
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
|
start_server
|
||||||
echo $! > "$PID_FILE"
|
echo $! > "$PID_FILE"
|
||||||
|
|
||||||
sleep 2
|
sleep 2
|
||||||
if kill -0 $(cat "$PID_FILE") 2>/dev/null; then
|
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
|
else
|
||||||
printf "${RED}启动失败,请查看 $LOG_FILE${NC}\n"
|
printf "${RED}Start failed, check $LOG_FILE${NC}\n"
|
||||||
rm -f "$PID_FILE"
|
rm -f "$PID_FILE"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
@@ -119,33 +135,34 @@ case "$1" in
|
|||||||
do_stop
|
do_stop
|
||||||
;;
|
;;
|
||||||
restart)
|
restart)
|
||||||
printf "${BLUE}正在执行彻底重启...${NC}\n"
|
printf "${BLUE}Restarting...${NC}\n"
|
||||||
do_stop
|
do_stop
|
||||||
sleep 1
|
sleep 1
|
||||||
rm -rf .next
|
rm -rf .next
|
||||||
do_start
|
do_start
|
||||||
;;
|
;;
|
||||||
logs)
|
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)
|
status)
|
||||||
if [ -n "$(get_port_pids)" ]; then
|
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
|
(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
|
else
|
||||||
printf "${RED}应用未运?{NC}\n"
|
printf "${RED}App is not running${NC}\n"
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
clean)
|
clean)
|
||||||
printf "${BLUE}清理缓存和日?..${NC}\n"
|
printf "${BLUE}Cleaning cache and logs...${NC}\n"
|
||||||
rm -rf .next "$LOG_FILE" "$PID_FILE"
|
rm -rf .next "$LOG_FILE" "$PID_FILE"
|
||||||
printf "${GREEN}清理完成${NC}\n"
|
printf "${GREEN}Clean complete${NC}\n"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
printf "${BLUE}STARK Todo List 本地管理脚本${NC}\n"
|
printf "${BLUE}STARK Todo List management script${NC}\n"
|
||||||
echo "用法: $0 [start|stop|restart|logs|status|clean]"
|
echo "Usage: $0 [start|stop|restart|logs|status|clean]"
|
||||||
exit 1
|
exit 1
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user