File size: 3,424 Bytes
3718c84
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
105
106
107
#!/bin/bash

# Script để kiểm tra và fix Cloudflare Tunnel trên Unraid

echo "============================================================"
echo "🔍 Kiểm tra Cloudflare Tunnel cho PostgreSQL"
echo "============================================================"
echo ""

TUNNEL_NAME="mystifying_bassi"
POSTGRES_CONTAINER="postgres-hue"
POSTGRES_HOST="192.168.1.212"
POSTGRES_PORT="5432"

# 1. Check tunnel container
echo "1️⃣  Kiểm tra tunnel container..."
if docker ps | grep -q "$TUNNEL_NAME"; then
    echo "✅ Tunnel container đang chạy"
    docker ps | grep "$TUNNEL_NAME"
else
    echo "❌ Tunnel container KHÔNG chạy!"
    exit 1
fi

# 2. Check PostgreSQL container
echo ""
echo "2️⃣  Kiểm tra PostgreSQL container..."
if docker ps | grep -q "$POSTGRES_CONTAINER"; then
    echo "✅ PostgreSQL container đang chạy"
    docker ps | grep "$POSTGRES_CONTAINER"
else
    echo "❌ PostgreSQL container KHÔNG chạy!"
    exit 1
fi

# 3. Test PostgreSQL locally
echo ""
echo "3️⃣  Test PostgreSQL từ trong Unraid..."
if docker exec "$POSTGRES_CONTAINER" psql -U hue_remote -d hue_portal -c "SELECT 1;" > /dev/null 2>&1; then
    echo "✅ PostgreSQL hoạt động OK"
else
    echo "❌ PostgreSQL KHÔNG hoạt động!"
    exit 1
fi

# 4. Check tunnel logs for postgres config
echo ""
echo "4️⃣  Kiểm tra tunnel config..."
if docker logs "$TUNNEL_NAME" --tail 50 | grep -q "postgres.aliss.io.vn.*tcp://$POSTGRES_HOST:$POSTGRES_PORT"; then
    echo "✅ Tunnel config có postgres.aliss.io.vn → tcp://$POSTGRES_HOST:$POSTGRES_PORT"
else
    echo "⚠️  KHÔNG tìm thấy config postgres trong logs"
    echo "   Xem logs:"
    docker logs "$TUNNEL_NAME" --tail 10 | grep -i "postgres\|tcp\|5432"
fi

# 5. Check tunnel connection status
echo ""
echo "5️⃣  Kiểm tra tunnel connection status..."
if docker logs "$TUNNEL_NAME" --tail 20 | grep -q "Registered tunnel connection"; then
    echo "✅ Tunnel đã connected"
    docker logs "$TUNNEL_NAME" --tail 5 | grep "Registered tunnel connection"
else
    echo "⚠️  Không thấy tunnel connection"
fi

# 6. Check for any connection attempts
echo ""
echo "6️⃣  Kiểm tra connection attempts (nếu có)..."
RECENT_LOGS=$(docker logs "$TUNNEL_NAME" --tail 100 | grep -i "request\|connection\|postgres\|5432" | tail -5)
if [ -n "$RECENT_LOGS" ]; then
    echo "📋 Recent logs:"
    echo "$RECENT_LOGS"
else
    echo "⚠️  Không có connection attempts gần đây"
fi

# 7. Suggestions
echo ""
echo "============================================================"
echo "💡 Gợi ý:"
echo "============================================================"
echo ""
echo "Nếu kết nối vẫn không hoạt động:"
echo ""
echo "1. Restart tunnel:"
echo "   docker restart $TUNNEL_NAME"
echo ""
echo "2. Đợi 30 giây và check logs:"
echo "   sleep 30"
echo "   docker logs $TUNNEL_NAME --tail 20"
echo ""
echo "3. Kiểm tra Cloudflare Dashboard:"
echo "   https://dash.cloudflare.com → Zero Trust → Networks → Tunnels"
echo "   - Xem tunnel status phải là 'Healthy'"
echo "   - Xem config có postgres.aliss.io.vn → tcp://$POSTGRES_HOST:$POSTGRES_PORT"
echo ""
echo "4. Test từ máy local:"
echo "   PGPASSWORD=huepass123 psql -h postgres.aliss.io.vn -p 5432 -U hue_remote -d hue_portal -c 'SELECT 1;'"
echo ""
echo "============================================================"