public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-commits] proj/netifrc:master commit in: init.d/, doc/
@ 2018-07-12  6:52 Robin H. Johnson
  0 siblings, 0 replies; only message in thread
From: Robin H. Johnson @ 2018-07-12  6:52 UTC (permalink / raw
  To: gentoo-commits

commit:     6f261f1beec1ecbfe7ec39ae33b5a7f947292f6e
Author:     Maciej S. Szmigiero <mail <AT> maciej <DOT> szmigiero <DOT> name>
AuthorDate: Wed Nov 29 19:49:27 2017 +0000
Commit:     Robin H. Johnson <robbat2 <AT> gentoo <DOT> org>
CommitDate: Thu Jul 12 06:51:03 2018 +0000
URL:        https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=6f261f1b

init.d/net.lo: add a configurable presence timeout

Sometimes one may want to wait for a particular interface to show up
when starting its service.
For example if a "net.foo" service is in the "default" runlevel so it
provides (or co-provides) the "net" service and it takes a while for the
"foo" interface to initialize and show up in the system during boot this
interface initialization will race with starting of this "net.foo" service
by the service manager - if the interface hasn't shown up yet the service
won't be able to start (and so will services that depend on it).

This setting specifies how long we'll wait for an interface to show up
in this case (in seconds).
For backward-compatibility the default is 0 (don't wait at all) - this
matches the existing behavior of netifrc, so existing deployments aren't
affected by this change.

This new setting is similar to an already present "wait for carrier
timeout" setting.

Signed-off-by: Maciej S. Szmigiero <mail <AT> maciej.szmigiero.name>
(cherry picked from commit 64f33a2032b4972a25cad6405678f678a5a269ff)
Closes: https://github.com/gentoo/netifrc/pull/28

 doc/net.example.BSD.in   | 16 ++++++++++++++++
 doc/net.example.Linux.in | 16 ++++++++++++++++
 init.d/net.lo.in         | 33 ++++++++++++++++++++++++++++++++-
 3 files changed, 64 insertions(+), 1 deletion(-)

diff --git a/doc/net.example.BSD.in b/doc/net.example.BSD.in
index 1df32e0..4c574b4 100644
--- a/doc/net.example.BSD.in
+++ b/doc/net.example.BSD.in
@@ -77,6 +77,22 @@
 # Some users may need to alter the MTU - here's how
 #mtu_eth0="1500"
 
+# Sometimes you may want to wait for a particular interface to show up
+# when starting its service.
+# For example if a net.foo service is in the "default" runlevel so it
+# provides (or co-provides) the "net" service and it takes a while for the
+# "foo" interface to initialize and show up in the system during a boot this
+# will race with starting of net.foo service by the service manager - if the
+# interface hasn't shown up yet the service won't be able start (and so
+# will services that depend on it).
+# This setting specifies how long we wait for an interface to show up
+# in this case (in seconds).
+# The current default is 0 - we need an interface to be already present
+# in the system when its service is started.
+#presence_timeout=0
+# This setting can be also adjusted on a per-interface basis:
+#presence_timeout_eth0=10
+
 # Most drivers that report carrier status function correctly, but some do not
 # One of these faulty drivers is for the Intel e1000 network card, but only
 # at boot time. To get around this you may alter the carrier_timeout value for

diff --git a/doc/net.example.Linux.in b/doc/net.example.Linux.in
index c0cfd38..3b414ba 100644
--- a/doc/net.example.Linux.in
+++ b/doc/net.example.Linux.in
@@ -126,6 +126,22 @@
 # tables you may have to set a global metric as the due to a simple read of
 # the routing table taking over a minute at a time.
 
+# Sometimes you may want to wait for a particular interface to show up
+# when starting its service.
+# For example if a net.foo service is in the "default" runlevel so it
+# provides (or co-provides) the "net" service and it takes a while for the
+# "foo" interface to initialize and show up in the system during a boot this
+# will race with starting of net.foo service by the service manager - if the
+# interface hasn't shown up yet the service won't be able start (and so
+# will services that depend on it).
+# This setting specifies how long we wait for an interface to show up
+# in this case (in seconds).
+# The current default is 0 - we need an interface to be already present
+# in the system when its service is started.
+#presence_timeout=0
+# This setting can be also adjusted on a per-interface basis:
+#presence_timeout_eth0=10
+
 # Most drivers that report carrier status function correctly, but some do not
 # One of these faulty drivers is for the Intel e1000 network card, but only
 # at boot time. To get around this you may alter the carrier_timeout value for

diff --git a/init.d/net.lo.in b/init.d/net.lo.in
index b78a342..472ed0c 100644
--- a/init.d/net.lo.in
+++ b/init.d/net.lo.in
@@ -118,6 +118,37 @@ _flatten_array()
 	_array_helper $1
 }
 
+_wait_for_presence()
+{
+	local timeout=
+	local rc=
+
+	_exists && return 0
+
+	eval timeout=\$presence_timeout_${IFVAR}
+	timeout=${timeout:-${presence_timeout:-0}}
+
+	[ ${timeout} -le 0 ] && return 1
+
+	einfon "Waiting for ${IFACE} to show up (${timeout} seconds)"
+	while [ ${timeout} -gt 0 ]; do
+		_exists
+		rc=$?
+		[ $rc -eq 0 ] && break
+
+		sleep 1
+		printf "."
+		: $(( timeout -= 1 ))
+	done
+
+	if [ ${timeout} -le 0 ]; then
+		_exists
+		rc=$?
+	fi
+	echo
+	eend $rc
+}
+
 _wait_for_carrier()
 {
 	local timeout=
@@ -618,7 +649,7 @@ start()
 		fi
 	done
 
-	if ! _exists; then
+	if ! _wait_for_presence; then
 		eerror "ERROR: interface ${IFACE} does not exist"
 		eerror "Ensure that you have loaded the correct kernel module for your hardware"
 		return 1


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2018-07-12  6:52 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-07-12  6:52 [gentoo-commits] proj/netifrc:master commit in: init.d/, doc/ Robin H. Johnson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox