tao-shen commited on
Commit
8d4595b
Β·
verified Β·
1 Parent(s): 17d78b9

Upload scripts/entrypoint.sh with huggingface_hub

Browse files
Files changed (1) hide show
  1. scripts/entrypoint.sh +39 -76
scripts/entrypoint.sh CHANGED
@@ -1,79 +1,42 @@
1
- #!/bin/sh
2
- set -e
3
-
4
- BOOT_START=$(date +%s)
5
-
6
- echo "[entrypoint] OpenClaw HuggingFace Spaces Entrypoint"
7
- echo "[entrypoint] ======================================="
8
-
9
- # ── DNS pre-resolution (background β€” non-blocking) ───────────────────────
10
- # Resolves WhatsApp domains via DoH for dns-fix.cjs to consume.
11
- # Telegram connectivity is handled by API base auto-probe in sync_hf.py.
12
- echo "[entrypoint] Starting DNS resolution in background..."
13
- python3 /home/node/scripts/dns-resolve.py /tmp/dns-resolved.json 2>&1 &
14
- DNS_PID=$!
15
- echo "[entrypoint] DNS resolver PID: $DNS_PID"
16
 
17
- # ── Node.js memory limit (only if explicitly set) ─────────────────────────
18
- if [ -n "$NODE_MEMORY_LIMIT" ]; then
19
- export NODE_OPTIONS="${NODE_OPTIONS:+$NODE_OPTIONS }--max-old-space-size=$NODE_MEMORY_LIMIT"
20
- echo "[entrypoint] Node.js memory limit: ${NODE_MEMORY_LIMIT}MB"
21
- fi
22
-
23
- # Enable Node.js DNS fix (will use resolved file when ready)
24
- export NODE_OPTIONS="${NODE_OPTIONS:+$NODE_OPTIONS }--require /home/node/scripts/dns-fix.cjs"
25
-
26
- # Enable Telegram API proxy (redirects fetch() to working mirror if needed)
27
- export NODE_OPTIONS="${NODE_OPTIONS:+$NODE_OPTIONS }--require /home/node/scripts/telegram-proxy.cjs"
28
-
29
- # Enable token redirect + A2A routing + state/agents endpoints (all in one preload)
30
- export NODE_OPTIONS="${NODE_OPTIONS:+$NODE_OPTIONS }--require /home/node/scripts/token-redirect.cjs"
31
 
32
- # ── Create .openclaw directory structure ─────────────────────────────────
33
- echo "[entrypoint] Setting up .openclaw directory structure..."
 
 
 
 
 
 
 
 
 
 
 
 
 
34
  mkdir -p /app/.openclaw
35
- # Copy the default configuration file if it doesn't exist
36
- if [ ! -f /app/.openclaw/openclaw.json ]; then
37
- cp /home/node/scripts/openclaw.json.default /app/.openclaw/openclaw.json
38
- echo "[entrypoint] Copied default openclaw.json config"
39
- fi
40
-
41
- # ── Extensions symlink ──────────────────────────────────────────────────────
42
- SYMLINK_START=$(date +%s)
43
- if [ ! -L /home/node/.openclaw/extensions ]; then
44
- rm -rf /home/node/.openclaw/extensions 2>/dev/null || true
45
- ln -s /app/openclaw/extensions /home/node/.openclaw/extensions
46
- echo "[entrypoint] Created extensions symlink -> /app/openclaw/extensions"
47
- fi
48
- echo "[TIMER] Extensions symlink: $(($(date +%s) - SYMLINK_START))s"
49
-
50
- # ── WhatsApp credentials check ──────────────────────────────────────────────
51
- if [ -d /home/node/.openclaw/credentials/whatsapp ]; then
52
- echo "[entrypoint] Found existing WhatsApp credentials - will use for auto-connect"
53
- fi
54
-
55
- # ── Build artifacts check ───────────────────────────────────────────────────
56
- cd /app/openclaw
57
- echo "[entrypoint] Build artifacts check:"
58
- test -f dist/entry.js && echo " OK dist/entry.js" || echo " INFO: dist/entry.js not found (pre-built image may use openclaw.mjs)"
59
- test -f openclaw.mjs && echo " OK openclaw.mjs" || echo " INFO: openclaw.mjs not found"
60
- test -f dist/plugin-sdk/index.js && echo " OK dist/plugin-sdk/index.js" || echo " INFO: dist/plugin-sdk/index.js not found"
61
- echo " Extensions: $(ls extensions/ 2>/dev/null | wc -l | tr -d ' ') found"
62
- echo " Global extensions link: $(readlink /home/node/.openclaw/extensions 2>/dev/null || echo 'NOT SET')"
63
-
64
- # Create logs directory
65
- mkdir -p /home/node/logs
66
- touch /home/node/logs/app.log
67
-
68
- ENTRYPOINT_END=$(date +%s)
69
- echo "[TIMER] Entrypoint (before sync_hf.py): $((ENTRYPOINT_END - BOOT_START))s"
70
-
71
- # ── Set version from build artifact ────────────────────────────────────────
72
- if [ -f /app/openclaw/.version ]; then
73
- export OPENCLAW_VERSION=$(cat /app/openclaw/.version)
74
- echo "[entrypoint] OpenClaw version: $OPENCLAW_VERSION"
75
- fi
76
-
77
- # ── Start OpenClaw via sync_hf.py (directly on port 7860, no proxy) ───────
78
- echo "[entrypoint] Starting OpenClaw via sync_hf.py..."
79
- exec python3 -u /home/node/scripts/sync_hf.py
 
1
+ #!/bin/bash
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
+ set -e
 
 
 
 
 
 
 
 
 
 
 
 
 
4
 
5
+ # Wait for DNS resolution
6
+ echo "Waiting for DNS resolution..."
7
+ for i in {1..30}; do
8
+ if nslookup cain-voice.hf.space > /dev/null 2>&1; then
9
+ break
10
+ fi
11
+ sleep 1
12
+ done
13
+
14
+ # Set environment variables
15
+ export OPENCLAW_HOST="http://localhost:7860"
16
+ export OPENCLAW_VOICE="default"
17
+ export OPENCLAW_LANGUAGE="en"
18
+
19
+ # Create necessary directories
20
  mkdir -p /app/.openclaw
21
+ mkdir -p /app/output
22
+
23
+ # Start OpenClaw in the background
24
+ echo "Starting OpenClaw..."
25
+ cd /app
26
+ nohup python -m openclaw.server --host 0.0.0.0 --port 7860 > openclaw.log 2>&1 &
27
+ OPENCLAW_PID=$!
28
+
29
+ # Wait for OpenClaw to start
30
+ echo "Waiting for OpenClaw to initialize..."
31
+ for i in {1..30}; do
32
+ if curl -f $OPENCLAW_HOST > /dev/null 2>&1; then
33
+ echo "OpenClaw is ready!"
34
+ break
35
+ fi
36
+ sleep 1
37
+ done
38
+
39
+ # Start the sync process
40
+ echo "Starting Cain..."
41
+ cd /app
42
+ python scripts/sync_hf.py