2015-10-20 04:36:55 +05:30
|
|
|
#!@SBINDIR@/openrc-run
|
2015-12-05 04:22:19 +05:30
|
|
|
# Copyright (c) 2015 The OpenRC Authors.
|
|
|
|
# See the Authors file at the top-level directory of this distribution and
|
|
|
|
# https://github.com/OpenRC/openrc/blob/master/AUTHORS
|
|
|
|
#
|
|
|
|
# This file is part of OpenRC. It is subject to the license terms in
|
|
|
|
# the LICENSE file found in the top-level directory of this
|
|
|
|
# distribution and at https://github.com/OpenRC/openrc/blob/master/LICENSE
|
|
|
|
# This file may not be copied, modified, propagated, or distributed
|
|
|
|
# except according to the terms contained in the LICENSE file.
|
2015-10-20 04:36:55 +05:30
|
|
|
|
|
|
|
description="Delays until the network is online or a specific timeout"
|
|
|
|
|
|
|
|
depend()
|
|
|
|
{
|
|
|
|
after modules
|
|
|
|
need sysfs
|
2017-02-27 01:21:50 +05:30
|
|
|
provide network-online
|
2016-07-31 23:31:17 +05:30
|
|
|
keyword -docker -jail -lxc -openvz -prefix -systemd-nspawn -uml -vserver
|
2015-10-20 04:36:55 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
get_interfaces()
|
|
|
|
{
|
|
|
|
local ifname iftype
|
|
|
|
for ifname in /sys/class/net/*; do
|
|
|
|
read iftype < ${ifname}/type
|
|
|
|
[ "$iftype" = "1" ] && printf "%s " ${ifname##*/}
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
start ()
|
|
|
|
{
|
2016-11-03 21:48:20 +05:30
|
|
|
local carriers configured dev gateway ifcount infinite
|
2017-12-10 03:48:03 +05:30
|
|
|
local carrier operstate rc
|
2015-10-20 04:36:55 +05:30
|
|
|
|
|
|
|
ebegin "Checking to see if the network is online"
|
|
|
|
rc=0
|
|
|
|
interfaces=${interfaces:-$(get_interfaces)}
|
|
|
|
timeout=${timeout:-120}
|
|
|
|
[ $timeout -eq 0 ] && infinite=true || infinite=false
|
|
|
|
while $infinite || [ $timeout -gt 0 ]; do
|
|
|
|
carriers=0
|
|
|
|
configured=0
|
|
|
|
ifcount=0
|
|
|
|
for dev in ${interfaces}; do
|
|
|
|
: $((ifcount += 1))
|
2017-12-13 00:15:52 +05:30
|
|
|
read carrier < /sys/class/net/$dev/carrier 2> /dev/null ||
|
|
|
|
carrier=
|
2017-12-12 05:11:04 +05:30
|
|
|
[ "$carrier" = 1 ] && : $((carriers += 1))
|
2017-12-13 00:15:52 +05:30
|
|
|
read operstate < /sys/class/net/$dev/operstate 2> /dev/null ||
|
|
|
|
operstate=
|
2017-12-10 03:48:03 +05:30
|
|
|
[ "$operstate" = up ] && : $((configured += 1))
|
2015-10-20 04:36:55 +05:30
|
|
|
done
|
|
|
|
[ $configured -eq $ifcount ] && [ $carriers -ge 1 ] && break
|
|
|
|
sleep 1
|
|
|
|
: $((timeout -= 1))
|
|
|
|
done
|
|
|
|
! $infinite && [ $timeout -eq 0 ] && rc=1
|
2017-02-27 01:21:50 +05:30
|
|
|
include_ping_test=${include_ping_test:-${ping_default_gateway}}
|
|
|
|
if [ -n "${ping_default_gateway}" ]; then
|
2017-02-27 06:39:56 +05:30
|
|
|
ewarn "ping_default_gateway is deprecated, please use include_ping_test"
|
2017-02-27 01:21:50 +05:30
|
|
|
fi
|
|
|
|
if [ $rc -eq 0 ] && yesno ${include_ping_test:-no}; then
|
|
|
|
ping_test_host="${ping_test_host:-google.com}"
|
|
|
|
if [ -n "$ping_test_host" ]; then
|
2017-12-13 02:21:55 +05:30
|
|
|
while $infinite || [ $timeout -gt 0 ]; do
|
|
|
|
ping -c 1 $ping_test_host > /dev/null 2>&1
|
|
|
|
rc=$?
|
|
|
|
[ $rc -eq 0 ] && break
|
|
|
|
: $((timeout -= 1))
|
|
|
|
done
|
2015-10-20 04:36:55 +05:30
|
|
|
fi
|
|
|
|
fi
|
|
|
|
eend $rc "The network is offline"
|
|
|
|
}
|