On 10/9/23 07:20, Simon Richter wrote:
Hi,
On 09.10.23 11:49, Jonathan Kamens wrote:
I need to be able to tell from one of my package scripts whether the
host has networking connectivity.
無. There is no such thing as "networking connectivity."
There is "has access to a particular service, at this precise moment in
time" and "is usually connected to an unmetered Internet connection so
there is a reasonable expectation that a particular service can be
reached and should be made part of a workflow."
I very much agree with Simon. There's all sorts of "networking
connectivity", partial or not. For example, would you consider that your
server has network connectivity if it only has L2 link local
connectivity to the neighboring switches? In some case, you shouldn't.
In some case (like using bgp-to-the-host setup), you should first check
if FRR is using it to provide wider connectivity. In the case of an
OpenStack cluster, in some setup, FRR would do that, but typically the
nodes don't have internet access.
After many wrong designs, I ended up having a process that pings the
service I need to access to, with a script like this one:
TRIALS=300
while ! timeout 2 ping -q -c 1 ${DST_SERVER} >/dev/null \
&& [ "${TRIALS}" -gt 0 ] ; do
sleep 1
TRIALS=$(( ${TRIALS} - 1 ))
done
if [ "${TRIALS}" = 0 ] ; then
exit 1
else
exit 0
fi
Since I use this, I never had any issue.
(comments on the above script welcome... one improvement would be using
a timestamp using date to write the timeout in seconds, but in this
particular instance, I don't really care, I just care the caller script
waits until there's connectivity)
Cheers,
Thomas Goirand (zigo)