Files
DanDing1Todo_Web/run.sh
Mr.Xia 0e74c56caf
Some checks failed
CI / lint (push) Has been cancelled
CI / build (push) Has been cancelled
run start 为生产环境
2026-02-27 10:49:26 +08:00

116 lines
2.8 KiB
Bash
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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.

#!/bin/bash
# --- 颜色定义 ---
GREEN='\033[0;32m'
BLUE='\033[0;34m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m'
PID_FILE="app.pid"
LOG_FILE="app.log"
# --- 逻è¾å°<C3A5>装 ---
function do_stop() {
printf "${YELLOW}正在å<EFBFBD>œæ­¢ STARK Todo List...${NC}\n"
# 1. é¦å…ˆå°<C3A5>试通过 PID æ‡ä»¶å<C2B6>œæ­¢
if [ -f "$PID_FILE" ]; then
PID=$(cat "$PID_FILE")
pkill -P $PID >/dev/null 2>&1
kill $PID >/dev/null 2>&1
rm "$PID_FILE"
fi
# 2. 强åŠå…œåº•:查找并æ<C2B6>€æ­»å<C2BB> ç”?2333 端å<C2AF>£çš„æ‰€æœ?Node 进程
PORT_PIDS=$(lsof -t -i:2333)
if [ -n "$PORT_PIDS" ]; then
for P in $PORT_PIDS; do
kill -9 $P >/dev/null 2>&1
done
fi
printf "${YELLOW}å·²å<EFBFBD>œæ­¢æ‰€æœ‰ç¸å…³è¿ç¨å¹¶é‡Šæ”¾ç«¯å<EFBFBD>£ã€?{NC}\n"
}
function do_start() {
if [ -f "$PID_FILE" ] && kill -0 $(cat "$PID_FILE") 2>/dev/null; then
printf "${YELLOW}应用已ç»<EFBFBD>在è¿<EFBFBD>行中 (PID: $(cat $PID_FILE))${NC}\n"
return 0
fi
PORT_PID=$(lsof -t -i:2333)
if [ -n "$PORT_PID" ]; then
printf "${RED}错误: 端å<C2AF>£ 2333 已被å<C2AB> ç”¨ï¼Œå°<C3A5>试执è¡?stop å<>Žå†<C3A5>å<EFBFBD>¯åЍ${NC}\n"
return 1
fi
printf "${GREEN}?? $PM ?? STARK Todo List (production)...${NC}\n"
# æŠåˆ¶å®‰è£…输出,ä¿<C3A4>æŒ<C3A6>界é<C592>¢æ•´æ´? $PM install > /dev/null 2>&1
$PM run build > /dev/null 2>&1
NODE_ENV=production nohup $PM run start > "$LOG_FILE" 2>&1 &
echo $! > "$PID_FILE"
sleep 2
if kill -0 $(cat "$PID_FILE") 2>/dev/null; then
printf "${GREEN}å<EFBFBD>¯åЍæˆ<EFBFBD>功ï¼<EFBFBD>访é—? http://localhost:2333${NC}\n"
else
printf "${RED}å<EFBFBD>¯åŠ¨å¤±è´¥ï¼Œè¯·æŸ¥çœ $LOG_FILE${NC}\n"
rm -f "$PID_FILE"
fi
}
# --- åˆ<C3A5>å§åŒ?---
if [ ! -f "todos.json" ]; then
echo "[]" > todos.json
printf "${YELLOW}å·²åˆå»ºåˆ<EFBFBD>å§æ•°æ<EFBFBD>®æ‡ä»?todos.json${NC}\n"
fi
# 检查包管ç<C2A1>†å™?
if command -v pnpm >/dev/null 2>&1; then
PM="pnpm"
else
PM="npm"
fi
case "$1" in
start)
do_start
;;
stop)
do_stop
;;
restart)
printf "${BLUE}正在执行彻底é‡<EFBFBD>å<EFBFBD>¯...${NC}\n"
do_stop
sleep 1
rm -rf .next
do_start
;;
logs)
[ -f "$LOG_FILE" ] && tail -f "$LOG_FILE" || printf "${RED}日志æ‡ä»¶ä¸<EFBFBD>å­˜åœ?{NC}\n"
;;
status)
if lsof -i:2333 >/dev/null 2>&1; then
printf "${GREEN}应用正在è¿<EFBFBD>行${NC}\n"
lsof -i:2333
else
printf "${RED}应用未è¿<EFBFBD>è¡?{NC}\n"
fi
;;
clean)
printf "${BLUE}清ç<EFBFBD>†ç¼“å­˜åŒæ—¥å¿?..${NC}\n"
rm -rf .next "$LOG_FILE" "$PID_FILE"
printf "${GREEN}清ç<EFBFBD>†å®Œæˆ<EFBFBD>${NC}\n"
;;
*)
printf "${BLUE}STARK Todo List 本地管ç<C2A1>†è„šæœ¬${NC}\n"
echo "用法: $0 [start|stop|restart|logs|status|clean]"
exit 1
;;
esac