Compare commits

..
2 Commits
Author SHA1 Message Date
hz4th_coder 79a1ca36c5 feat: 添加 keepalive 保活脚本 + cron 定时检查
- 每5分钟检查服务是否运行
- 自动杀掉占用端口的非 node 进程(如 Python http.server)
- 自动重启 node 服务
2026-07-24 17:34:02 +08:00
hz4th_coder a6c8de5820 fix: 修复表格模式无法显示的问题
1. 修复 registerFont API 调用 - @napi-rs/canvas 使用 GlobalFonts.registerFromPath 而非 registerFont
2. 确保 Express 服务端正确启动(之前误用 Python http.server 导致 POST 请求返回 501)
2026-07-24 16:17:32 +08:00
2 changed files with 49 additions and 2 deletions
Executable
+45
View File
@@ -0,0 +1,45 @@
#!/bash
# data-chart-tool 保活脚本
# 检查服务是否运行,如果没有则启动
PORT=16016
APP_DIR="/home/openclaw/.openclaw/workspace-hz4th_coder/works/data-chart-tool"
LOG_FILE="$APP_DIR/logs/server.log"
# 检查端口是否被占用
if ss -tlnp | grep -q ":$PORT "; then
# 检查是不是 node 进程
PID=$(ss -tlnp | grep ":$PORT " | grep -oP 'pid=\K[0-9]+' | head -1)
if [ -n "$PID" ]; then
CMD=$(ps -p "$PID" -o comm= 2>/dev/null)
if [ "$CMD" = "node" ] || [ "$CMD" = "MainThread" ]; then
# node 服务在运行,检查是否正常响应
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:$PORT/api/health 2>/dev/null)
if [ "$HTTP_CODE" = "200" ]; then
echo "[$(date)] Service OK (PID=$PID, HTTP=$HTTP_CODE)"
exit 0
fi
fi
# 端口被非 node 进程占用(如 Python http.server),杀掉它
echo "[$(date)] Port $PORT occupied by $CMD (PID=$PID), killing..."
kill -9 "$PID" 2>/dev/null
sleep 1
fi
fi
# 启动 node 服务
echo "[$(date)] Starting data-chart-tool..."
cd "$APP_DIR"
nohup node server.js >> "$LOG_FILE" 2>&1 &
echo "[$(date)] Started with PID $!"
# 等待启动
sleep 2
# 验证
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:$PORT/api/health 2>/dev/null)
if [ "$HTTP_CODE" = "200" ]; then
echo "[$(date)] Service started successfully (HTTP=$HTTP_CODE)"
else
echo "[$(date)] WARNING: Service may not have started correctly (HTTP=$HTTP_CODE)"
fi
+4 -2
View File
@@ -6,8 +6,10 @@ const path = require('path');
// 注册中文字体
try {
registerFont('/usr/share/fonts/opentype/noto/NotoSansCJK-Regular.ttc', { family: 'Noto Sans CJK SC' });
registerFont('/usr/share/fonts/opentype/noto/NotoSansCJK-Bold.ttc', { family: 'Noto Sans CJK SC', weight: 'bold' });
const { GlobalFonts } = require('@napi-rs/canvas');
GlobalFonts.registerFromPath('/usr/share/fonts/opentype/noto/NotoSansCJK-Regular.ttc', 'Noto Sans CJK SC');
GlobalFonts.registerFromPath('/usr/share/fonts/opentype/noto/NotoSansCJK-Bold.ttc', 'Noto Sans CJK SC');
console.log('中文字体注册成功');
} catch (e) {
console.warn('中文字体注册失败,将使用系统默认字体:', e.message);
}