Spaces:
Build error
Build error
fix: qr detection reliability and log piping
Browse files- scripts/entrypoint.sh +9 -3
- scripts/qr-detection-manager.cjs +11 -2
scripts/entrypoint.sh
CHANGED
|
@@ -75,13 +75,19 @@ echo "[entrypoint] Starting OpenClaw gateway on port 7860..."
|
|
| 75 |
echo "[entrypoint] WhatsApp login guardian started (PID $!)"
|
| 76 |
) &
|
| 77 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
# ── 启动 QR Code Detection Manager (BLOCKING CHECK) ──
|
| 79 |
-
#
|
| 80 |
-
# 这里我们让它并行运行,监控文件系统和日志
|
| 81 |
(
|
| 82 |
sleep 10
|
|
|
|
| 83 |
NODE_PATH=/app/openclaw/node_modules node /home/node/scripts/qr-detection-manager.cjs "${SPACE_HOST:-https://huggingface.co/spaces/tao-shen/openclaw-ai}" &
|
| 84 |
echo "[entrypoint] QR Detection Manager started (PID $!)"
|
| 85 |
) &
|
| 86 |
|
| 87 |
-
|
|
|
|
|
|
| 75 |
echo "[entrypoint] WhatsApp login guardian started (PID $!)"
|
| 76 |
) &
|
| 77 |
|
| 78 |
+
|
| 79 |
+
# Create logs directory
|
| 80 |
+
mkdir -p /home/node/logs
|
| 81 |
+
touch /home/node/logs/app.log
|
| 82 |
+
|
| 83 |
# ── 启动 QR Code Detection Manager (BLOCKING CHECK) ──
|
| 84 |
+
# 监控 logs/app.log
|
|
|
|
| 85 |
(
|
| 86 |
sleep 10
|
| 87 |
+
# Pass the log file path explicitly if needed, or rely on default
|
| 88 |
NODE_PATH=/app/openclaw/node_modules node /home/node/scripts/qr-detection-manager.cjs "${SPACE_HOST:-https://huggingface.co/spaces/tao-shen/openclaw-ai}" &
|
| 89 |
echo "[entrypoint] QR Detection Manager started (PID $!)"
|
| 90 |
) &
|
| 91 |
|
| 92 |
+
# 使用 tee 同时输出到 stdout (供 HF Logs) 和文件 (供 QR Manager)
|
| 93 |
+
exec node openclaw.mjs gateway 2>&1 | tee -a /home/node/logs/app.log
|
scripts/qr-detection-manager.cjs
CHANGED
|
@@ -42,7 +42,9 @@ class QRDetectionManager {
|
|
| 42 |
|
| 43 |
async connectWebSocket(spaceUrl) {
|
| 44 |
try {
|
| 45 |
-
|
|
|
|
|
|
|
| 46 |
const fullWsUrl = `${wsUrl}/queue/join`;
|
| 47 |
|
| 48 |
this.log('info', 'Connecting to WebSocket', { url: fullWsUrl });
|
|
@@ -70,7 +72,12 @@ class QRDetectionManager {
|
|
| 70 |
this.log('error', 'Failed to connect to WebSocket', { error: error.message });
|
| 71 |
}
|
| 72 |
}
|
| 73 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
startMonitoring() {
|
| 75 |
this.log('info', 'Starting QR code monitoring');
|
| 76 |
|
|
@@ -135,6 +142,8 @@ class QRDetectionManager {
|
|
| 135 |
checkLogsForQR() {
|
| 136 |
try {
|
| 137 |
const logPaths = [
|
|
|
|
|
|
|
| 138 |
'./logs/output.log',
|
| 139 |
'./logs/app.log',
|
| 140 |
'./logs/whatsapp.log',
|
|
|
|
| 42 |
|
| 43 |
async connectWebSocket(spaceUrl) {
|
| 44 |
try {
|
| 45 |
+
// Handle spaceUrl being just a hostname or full URL
|
| 46 |
+
let host = spaceUrl.replace(/^https?:\/\//, '').replace(/\/$/, '');
|
| 47 |
+
const wsUrl = `wss://${host}`;
|
| 48 |
const fullWsUrl = `${wsUrl}/queue/join`;
|
| 49 |
|
| 50 |
this.log('info', 'Connecting to WebSocket', { url: fullWsUrl });
|
|
|
|
| 72 |
this.log('error', 'Failed to connect to WebSocket', { error: error.message });
|
| 73 |
}
|
| 74 |
}
|
| 75 |
+
|
| 76 |
+
handleWebSocketMessage(data) {
|
| 77 |
+
// Placeholder for future WS message handling if needed
|
| 78 |
+
// Currently we rely mostly on log/file monitoring
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
startMonitoring() {
|
| 82 |
this.log('info', 'Starting QR code monitoring');
|
| 83 |
|
|
|
|
| 142 |
checkLogsForQR() {
|
| 143 |
try {
|
| 144 |
const logPaths = [
|
| 145 |
+
'/home/node/logs/app.log', // Main app log (redirected)
|
| 146 |
+
'/home/node/logs/app.json.log', // Structured log
|
| 147 |
'./logs/output.log',
|
| 148 |
'./logs/app.log',
|
| 149 |
'./logs/whatsapp.log',
|