Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
79a1ca36c5 | ||
|
|
a6c8de5820 |
Executable
+45
@@ -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
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user