Skip to content

Commit c878066

Browse files
authored
Update cloudflared.sh
Adjustments regarding the connection timeout and messages
1 parent 232b7fa commit c878066

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

cloudflared.sh

+15-8
Original file line numberDiff line numberDiff line change
@@ -8,36 +8,43 @@ echo -e "\033[0;34m────────────────────
88

99
# [Tunnel] Check if cloudflared_token.txt exists and has content
1010
if [ -s "/home/container/cloudflared_token.txt" ]; then
11-
echo -e "\033[0;37m[Tunnel] Starting Cloudflared with token...\033[0m"
11+
echo -e "\033[0;37m[Tunnel] Starting Cloudflared with token\033[0m"
1212

1313
# Start cloudflared in the background and store the PID
1414
cloudflared tunnel --no-autoupdate run --token "$(cat /home/container/cloudflared_token.txt)" > /home/container/logs/cloudflared.log 2>&1 &
1515
CLOUD_FLARED_PID=$!
1616

1717
echo $CLOUD_FLARED_PID > /home/container/tmp/cloudflared.pid
1818

19-
# Display waiting message
20-
echo -ne "\033[0;33m[Tunnel] Waiting for Cloudflared to start\033[0m"
21-
22-
MAX_ATTEMPTS=10
19+
MAX_ATTEMPTS=130
2320
ATTEMPT=0
2421

22+
# Times for status messages (seconds)
23+
STATUS_TIMES=(5 10 15 30 60 90 120)
24+
25+
# Display waiting message
26+
echo -e "\033[0;33m[Tunnel] Waiting for Cloudflared to start...\033[0m"
27+
2528
# Monitor log file in real-time for a success or failure message
2629
while [ $ATTEMPT -lt $MAX_ATTEMPTS ]; do
27-
echo -ne "." # Add a dot every second
2830
sleep 1
2931
ATTEMPT=$((ATTEMPT + 1))
3032

33+
if [[ " ${STATUS_TIMES[@]} " =~ " $ATTEMPT " ]]; then
34+
echo -e "\033[0;33m[Tunnel] Still waiting... ($ATTEMPT sec)\033[0m"
35+
fi
36+
3137
# Check if cloudflared has exited
3238
if ! kill -0 $CLOUD_FLARED_PID 2>/dev/null; then
33-
echo -e "\n\033[0;31m[Tunnel] Cloudflared failed to start. Check logs at /home/container/logs/cloudflared.log\033[0m"
39+
echo -e "\033[0;31m[Tunnel] Cloudflared failed to start. Check logs at /home/container/logs/cloudflared.log\033[0m"
3440
echo -e "\033[0;31m$(tail -n 10 /home/container/logs/cloudflared.log)\033[0m"
3541
exit 1
3642
fi
3743

3844
# Check log file for success messages
3945
if grep -qE "Registered tunnel connection|Updated to new configuration" /home/container/logs/cloudflared.log; then
40-
echo -e "\n\033[0;32m[Tunnel] Cloudflared is running successfully!\033[0m"
46+
echo -e "\033[0;32m[Tunnel] Connected after $ATTEMPT seconds\033[0m"
47+
echo -e "\033[0;32m[Tunnel] Cloudflared is running successfully!\033[0m"
4148
exit 0
4249
fi
4350
done

0 commit comments

Comments
 (0)