File size: 3,543 Bytes
30c96cf
 
ec2cf00
30c96cf
9295287
30c96cf
 
 
 
 
9295287
30c96cf
 
d69ade2
30c96cf
 
 
 
 
 
a853e62
30c96cf
 
 
 
 
6505ff1
30c96cf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d69ade2
30c96cf
 
 
9295287
30c96cf
 
 
 
9295287
30c96cf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/bin/bash
set -e

echo "🦞 Starting OpenClaw setup..."

# 1. Tạo thư mục cần thiết
mkdir -p /root/.openclaw/agents/main/sessions
mkdir -p /root/.openclaw/workspace/skills
mkdir -p /root/.openclaw/reports
mkdir -p /root/.openclaw/logs

# 2. Khôi phục dữ liệu từ Dataset
python3 /app/sync.py restore || echo "No existing backup."

# 3. Nạp Skills
echo "📦 Đang nạp Skills..."
cd /root/.openclaw/workspace
npx clawhub@latest install reddit-readonly --force || true
# Đã tạm tắt skill nofx vì không đăng ký được key
# npx clawhub@latest install nofx-ai500-report --force || true

if [ -d /app/skills ]; then
    cp -r /app/skills/* /root/.openclaw/workspace/skills/ 2>/dev/null || true
    echo "✅ Custom skills loaded."
fi
cd /app

# 4. Cấu hình OpenClaw (Grok 4.1 Fast)
cat > /root/.openclaw/openclaw.json <<EOF
{
  "models": {
    "providers": {
      "openai": {
        "apiKey": "$GROK_API_KEY",
        "baseUrl": "https://api.x.ai/v1",
        "models": [
          {
            "id": "grok-4-1-fast-non-reasoning",
            "name": "Grok 4.1 Fast (Non-Reasoning)",
            "contextWindow": 2000000
          }
        ]
      }
    }
  },
  "agents": {
    "defaults": {
      "model": {
        "primary": "openai/grok-4-1-fast-non-reasoning"
      },
      "timeoutSeconds": 120
    }
  },
  "gateway": {
    "mode": "local",
    "bind": "lan",
    "port": 7860,
    "trustedProxies": ["10.0.0.0/8"],
    "auth": {
      "mode": "token",
      "token": "$OPENCLAW_GATEWAY_PASSWORD"
    },
    "controlUi": {
      "enabled": true,
      "allowedOrigins": ["*"],
      "dangerouslyDisableDeviceAuth": true,
      "allowInsecureAuth": true
    }
  }
}
EOF

# 5. Khởi động vòng lặp Backup (Mỗi 10 phút)
(while true; do sleep 600; python3 /app/sync.py backup >> /root/.openclaw/logs/backup.log 2>&1; done) &
echo "🔄 Backup loop started."

# ==========================================
# 6. MỞ KHÓA CRON JOBS (HỆ THỐNG TỰ ĐỘNG)
# ==========================================
echo "⏳ Setting up automated tasks..."

# Cài đặt cron service nếu chưa có (vì base image của Hugging Face có thể thiếu)
apt-get update && apt-get install -y cron || true

cat > /etc/cron.d/openclaw-tasks <<EOF
# Run Signal Detector every 5 minutes
*/5 * * * * root curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer $OPENCLAW_GATEWAY_PASSWORD" -d '{"prompt": "Analyze BTCUSDT market and generate trading signals. Output JSON only."}' http://localhost:7860/v1/agents/main/run >> /root/.openclaw/logs/cron_signal.log 2>&1

# Run Technical Analysis every 2 hours
0 */2 * * * root curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer $OPENCLAW_GATEWAY_PASSWORD" -d '{"prompt": "Perform detailed technical analysis for BTCUSDT and generate a markdown report."}' http://localhost:7860/v1/agents/main/run >> /root/.openclaw/logs/cron_ta.log 2>&1

# Run SEO Report every 6 hours
0 */6 * * * root curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer $OPENCLAW_GATEWAY_PASSWORD" -d '{"prompt": "Generate a comprehensive SEO-optimized market report for the crypto community."}' http://localhost:7860/v1/agents/main/run >> /root/.openclaw/logs/cron_seo.log 2>&1
EOF

chmod 0644 /etc/cron.d/openclaw-tasks
crontab /etc/cron.d/openclaw-tasks
service cron start
echo "✅ Cron jobs activated!"
# ==========================================

export PORT=7860
echo "🚀 Starting gateway..."
exec openclaw gateway run