mirror of
https://github.com/KingHWJ/WeReadBoard.git
synced 2026-11-03 18:24:58 +08:00
前端: - 书架筛选栏新增「↻ 刷新」按钮,点击重新加载分类和书架数据 - 新增 refreshShelf() 函数,带 loading 状态反馈 - 新增 .shelf-refresh-btn CSS 样式 后端保活: - 新增 start_server.sh 启动脚本 (start/daemon/stop/restart/status) - 新增 com.weread-dashboard.plist launchd 服务配置 - KeepAlive=true: 崩溃自动重启 - RunAtLoad=true: 开机自动启动 - 日志输出到 /tmp/weread_server.log
109 lines
2.7 KiB
Bash
Executable File
109 lines
2.7 KiB
Bash
Executable File
#!/bin/bash
|
|
# 微信读书数据看板 - 服务启动脚本
|
|
# 用法:
|
|
# ./start_server.sh 启动服务(前台运行)
|
|
# ./start_server.sh daemon 后台守护进程方式启动
|
|
# ./start_server.sh stop 停止服务
|
|
# ./start_server.sh restart 重启服务
|
|
# ./start_server.sh status 查看状态
|
|
|
|
PROJECT_DIR="/Users/hwj/WorkBuddy/2026-07-17-09-48-20"
|
|
PYTHON="/Users/hwj/.workbuddy/binaries/python/envs/default/bin/python"
|
|
PID_FILE="$PROJECT_DIR/.server.pid"
|
|
LOG_FILE="/tmp/weread_server.log"
|
|
PORT=8080
|
|
|
|
cd "$PROJECT_DIR" || exit 1
|
|
|
|
is_running() {
|
|
if [ -f "$PID_FILE" ]; then
|
|
local pid=$(cat "$PID_FILE")
|
|
if kill -0 "$pid" 2>/dev/null; then
|
|
return 0
|
|
fi
|
|
fi
|
|
# 也检查端口是否被占用
|
|
if lsof -i :$PORT -t >/dev/null 2>&1; then
|
|
return 0
|
|
fi
|
|
return 1
|
|
}
|
|
|
|
get_pid() {
|
|
if [ -f "$PID_FILE" ]; then
|
|
local pid=$(cat "$PID_FILE")
|
|
if kill -0 "$pid" 2>/dev/null; then
|
|
echo "$pid"
|
|
return
|
|
fi
|
|
fi
|
|
lsof -i :$PORT -t 2>/dev/null | head -1
|
|
}
|
|
|
|
stop_server() {
|
|
if is_running; then
|
|
local pid=$(get_pid)
|
|
echo "停止服务 (PID: $pid)..."
|
|
kill "$pid" 2>/dev/null
|
|
sleep 1
|
|
if kill -0 "$pid" 2>/dev/null; then
|
|
kill -9 "$pid" 2>/dev/null
|
|
fi
|
|
rm -f "$PID_FILE"
|
|
echo "已停止"
|
|
else
|
|
echo "服务未运行"
|
|
fi
|
|
}
|
|
|
|
start_foreground() {
|
|
if is_running; then
|
|
echo "服务已在运行 (PID: $(get_pid))"
|
|
exit 1
|
|
fi
|
|
echo "启动服务(前台模式)..."
|
|
exec "$PYTHON" app.py
|
|
}
|
|
|
|
start_daemon() {
|
|
if is_running; then
|
|
echo "服务已在运行 (PID: $(get_pid))"
|
|
exit 1
|
|
fi
|
|
echo "启动服务(后台守护模式)..."
|
|
nohup "$PYTHON" app.py > "$LOG_FILE" 2>&1 &
|
|
local pid=$!
|
|
echo "$pid" > "$PID_FILE"
|
|
sleep 2
|
|
if kill -0 "$pid" 2>/dev/null; then
|
|
echo "服务已启动 (PID: $pid)"
|
|
echo "访问: http://127.0.0.1:$PORT"
|
|
echo "日志: $LOG_FILE"
|
|
else
|
|
echo "启动失败,请查看日志: $LOG_FILE"
|
|
cat "$LOG_FILE"
|
|
rm -f "$PID_FILE"
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
show_status() {
|
|
if is_running; then
|
|
local pid=$(get_pid)
|
|
echo "✅ 服务运行中 (PID: $pid)"
|
|
echo " 端口: $PORT"
|
|
echo " 日志: $LOG_FILE"
|
|
else
|
|
echo "❌ 服务未运行"
|
|
fi
|
|
}
|
|
|
|
case "${1:-start}" in
|
|
start) start_foreground ;;
|
|
daemon) start_daemon ;;
|
|
stop) stop_server ;;
|
|
restart) stop_server; sleep 1; start_daemon ;;
|
|
status) show_status ;;
|
|
*) echo "用法: $0 {start|daemon|stop|restart|status}"; exit 1 ;;
|
|
esac
|