@@ -31,22 +31,34 @@ function check_online
31
31
{
32
32
echo " Checking network connectivity..."
33
33
34
- echo " Running ping to 8.8.8.8 option"
35
- checks=0
36
- while true ; do
37
- if ping 8.8.8.8 -c 1 -i .2 -t 30; then
38
- echo " Network is accessible"
39
- return 0
40
- fi
41
- checks=$(( checks + 1 ))
42
- if [ $checks -gt 10 ]; then
43
- break
44
- fi
34
+ echo " Connecting to ifconfig.io to check network connection"
35
+ if command -v curl > /dev/null 2>&1 ; then
36
+ curl --retry 5 --retry-delay 5 --connect-timeout 5 -4 ifconfig.io/ip
37
+ elif command -v wget > /dev/null 2>&1 ; then
38
+ wget --tries=5 --timeout=5 --wait=5 -4 ifconfig.io/ip
39
+ else
40
+ http_get.py " http://ifconfig.io/ip" --timeout 5 --delay 5 --tries 5
41
+ fi
45
42
43
+ if [[ $? -eq 0 ]]; then
44
+ echo " Network is accessible"
45
+ return 0
46
+ else
46
47
echo " $( date --utc +%FT%T.%3NZ) : Network still not accessible"
47
- # We're offline. Sleep for a bit, then check again
48
- sleep 1;
49
- done
48
+ fi
49
+
50
+ echo " Running ping to 8.8.8.8 option"
51
+
52
+ if ping 8.8.8.8 -c 1 -i .2 -t 30; then
53
+ echo " Network is accessible"
54
+ return 0
55
+ fi
56
+
57
+ echo " $( date --utc +%FT%T.%3NZ) : Network still not accessible"
58
+ echo " Unable to connect to network, giving up"
59
+ return 1
60
+
61
+ # Will remove other options if we determine first option is stable
50
62
51
63
echo " Checking other options to see if network is accessible..."
52
64
77
89
echo " Finally online, Time: $( date --utc +%FT%T.%3NZ) "
78
90
echo " Trying to contact Wireserver as $USER to see if accessible"
79
91
echo " "
92
+
93
+ # This script is run by a cron job on reboot, so it runs in a limited environment. Some distros may be missing the iptables path,
94
+ # so adding common iptables paths to the environment.
95
+ export PATH=$PATH :/usr/sbin:/sbin
80
96
echo " Firewall configuration before accessing Wireserver:"
81
- if sudo which iptables > /dev/null ; then
82
- sudo iptables -t security -L -nxv -w
83
- else
97
+ if ! sudo iptables -t security -L -nxv -w; then
84
98
sudo nft list table walinuxagent
85
99
fi
86
100
echo " "
@@ -89,7 +103,7 @@ WIRE_IP=$(cat /var/lib/waagent/WireServerEndpoint 2>/dev/null || echo '168.63.12
89
103
if command -v curl > /dev/null 2>&1 ; then
90
104
curl --retry 3 --retry-delay 5 --connect-timeout 5 " http://$WIRE_IP /?comp=versions" -o " /tmp/wire-versions-$USER .xml"
91
105
elif command -v wget > /dev/null 2>&1 ; then
92
- wget --tries=3 " http://$WIRE_IP /?comp=versions" --timeout=5 -O " /tmp/wire-versions-$USER .xml" else
106
+ wget --tries=3 " http://$WIRE_IP /?comp=versions" --timeout=5 --wait=5 - O " /tmp/wire-versions-$USER .xml"
93
107
else
94
108
http_get.py " http://168.63.129.16/?comp=versions" --timeout 5 --delay 5 --tries 3
95
109
fi
0 commit comments