-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentrypoint.sh
More file actions
142 lines (117 loc) · 5.91 KB
/
entrypoint.sh
File metadata and controls
142 lines (117 loc) · 5.91 KB
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!/bin/bash
set -e
echo "Starting DeviceLab Appium Test Node..."
echo "DeviceLab URL: $DEVICELAB_URL"
echo "APK Path: /root/Downloads/app-release.apk"
echo "Test Node Port: $TEST_NODE_PORT"
echo "Network Mode: ${NETWORK_MODE:-bridge}"
# Network diagnostics and optimization for WebRTC/UDP in Docker
echo ""
echo "========================================="
echo "Network Configuration and Diagnostics"
echo "========================================="
# Display current network buffer sizes
echo "Initial UDP buffer sizes:"
echo " rmem_default: $(cat /proc/sys/net/core/rmem_default 2>/dev/null || echo 'N/A') bytes"
echo " wmem_default: $(cat /proc/sys/net/core/wmem_default 2>/dev/null || echo 'N/A') bytes"
echo " rmem_max: $(cat /proc/sys/net/core/rmem_max 2>/dev/null || echo 'N/A') bytes"
echo " wmem_max: $(cat /proc/sys/net/core/wmem_max 2>/dev/null || echo 'N/A') bytes"
echo " netdev_max_backlog: $(cat /proc/sys/net/core/netdev_max_backlog 2>/dev/null || echo 'N/A')"
# Apply network optimizations for WebRTC/UDP
echo ""
echo "Applying network optimizations for WebRTC/UDP..."
# Increase UDP buffer sizes (critical for WebRTC)
sysctl -w net.core.rmem_default=1048576 2>/dev/null || echo " Warning: Could not set rmem_default (may need privileged mode)"
sysctl -w net.core.wmem_default=1048576 2>/dev/null || echo " Warning: Could not set wmem_default (may need privileged mode)"
sysctl -w net.core.rmem_max=2097152 2>/dev/null || echo " Warning: Could not set rmem_max (may need privileged mode)"
sysctl -w net.core.wmem_max=2097152 2>/dev/null || echo " Warning: Could not set wmem_max (may need privileged mode)"
sysctl -w net.core.netdev_max_backlog=5000 2>/dev/null || echo " Warning: Could not set netdev_max_backlog"
# UDP specific settings
sysctl -w net.ipv4.udp_rmem_min=8192 2>/dev/null || true
sysctl -w net.ipv4.udp_wmem_min=8192 2>/dev/null || true
# MTU and fragmentation settings
sysctl -w net.ipv4.tcp_mtu_probing=1 2>/dev/null || true
sysctl -w net.ipv4.ip_no_pmtu_disc=0 2>/dev/null || true
# Connection tracking settings for UDP (if available)
sysctl -w net.netfilter.nf_conntrack_udp_timeout=300 2>/dev/null || true
sysctl -w net.netfilter.nf_conntrack_udp_timeout_stream=300 2>/dev/null || true
sysctl -w net.netfilter.nf_conntrack_max=65536 2>/dev/null || true
sysctl -w net.netfilter.nf_conntrack_generic_timeout=300 2>/dev/null || true
# Display updated buffer sizes
echo ""
echo "Updated UDP buffer sizes:"
echo " rmem_default: $(cat /proc/sys/net/core/rmem_default 2>/dev/null || echo 'N/A') bytes ($(( $(cat /proc/sys/net/core/rmem_default 2>/dev/null || echo 0) / 1024 )) KB)"
echo " wmem_default: $(cat /proc/sys/net/core/wmem_default 2>/dev/null || echo 'N/A') bytes ($(( $(cat /proc/sys/net/core/wmem_default 2>/dev/null || echo 0) / 1024 )) KB)"
echo " rmem_max: $(cat /proc/sys/net/core/rmem_max 2>/dev/null || echo 'N/A') bytes ($(( $(cat /proc/sys/net/core/rmem_max 2>/dev/null || echo 0) / 1024 )) KB)"
echo " wmem_max: $(cat /proc/sys/net/core/wmem_max 2>/dev/null || echo 'N/A') bytes ($(( $(cat /proc/sys/net/core/wmem_max 2>/dev/null || echo 0) / 1024 )) KB)"
# Network interface information
echo ""
echo "Network interfaces:"
ip addr show 2>/dev/null | grep -E "^[0-9]+:|inet " || ifconfig 2>/dev/null || echo "Could not get network interfaces"
# MTU information
echo ""
echo "MTU settings:"
ip link show | grep -E "^[0-9]+:|mtu" 2>/dev/null || echo "Could not get MTU information"
# Check for host network mode advantages
if [ "${NETWORK_MODE}" = "host" ]; then
echo ""
echo "✅ Running in HOST network mode - optimal for WebRTC/UDP performance"
else
echo ""
echo "⚠️ Running in BRIDGE network mode - may experience WebRTC/UDP issues"
echo " Consider using 'network-mode: host' for better performance"
fi
# Initial network statistics
echo ""
echo "Initial network statistics:"
netstat -su 2>/dev/null | grep -A 10 "Udp:" | head -15 || echo "Could not get UDP statistics"
echo "========================================="
echo ""
# Check if APK exists
if [ ! -f "/root/Downloads/app-release.apk" ]; then
echo "Error: APK file not found at /root/Downloads/app-release.apk"
exit 1
fi
# Display APK info
apk_size=$(stat -c%s "/root/Downloads/app-release.apk")
echo "APK Size: $(numfmt --to=iec $apk_size)"
# Function to monitor network stats in background
monitor_network_stats() {
local log_file="/var/log/network_monitor.log"
echo "[Network Monitor] Started at $(date)" > "$log_file"
while true; do
sleep 60
{
echo ""
echo "[Network Monitor] $(date '+%Y-%m-%d %H:%M:%S')"
echo "----------------------------------------"
# UDP statistics
echo "UDP Statistics:"
netstat -su 2>/dev/null | grep -A 10 "Udp:" | grep -E "packets|errors|buffer" || true
# Connection tracking (if available)
if command -v conntrack &> /dev/null; then
echo ""
echo "UDP Connection Tracking (top 5):"
conntrack -L 2>/dev/null | grep udp | head -5 || true
echo "Total UDP connections: $(conntrack -L 2>/dev/null | grep -c udp || echo 0)"
fi
# Network errors
echo ""
echo "Network Interface Errors:"
ip -s link 2>/dev/null | grep -A 1 "errors" | head -10 || true
echo "----------------------------------------"
} >> "$log_file" 2>&1
done
}
# Create log directory
mkdir -p /var/log
# Start network monitoring in background (non-blocking)
if [ "${ENABLE_NETWORK_MONITOR:-true}" = "true" ]; then
monitor_network_stats &
MONITOR_PID=$!
echo "Started network monitoring (PID: $MONITOR_PID, Log: /var/log/network_monitor.log)"
fi
# Download and execute DeviceLab script
echo ""
echo "Downloading and executing DeviceLab script..."
exec curl -fsSL "$DEVICELAB_URL" | sh -s -- --framework appium --app /root/Downloads/app-release.apk