Alternative way to wait interfaces on bootup
cover Alternative way to wait interfaces on bootup
As discussed here:
http://lists.busybox.net/pipermail/buildroot/2015-October/142329.html
J?r?me Pouiller (3):
Revert "package/initscripts: S40network: wait for network interfaces
to appear"
skeleton: optionally wait for network interfaces to appear
skeleton: wait interface to appear if dhcp is enabled
package/initscripts/init.d/S40network | 29 ---------------------- package/skeleton/skeleton.mk | 1 + system/skeleton/etc/network/if-pre-up.d/wait_iface | 28 +++++++++++++++++++++ 3 files changed, 29 insertions(+), 29 deletions(-) create mode 100755 system/skeleton/etc/network/if-pre-up.d/wait_iface
Signature · 1 line
2.1.4
PATCH 1/3 Revert "package/initscripts: S40network: wait for network interfaces to appear"
This reverts commit 49964858f45d2243c513e6d362e992ad89ec7a45. It is going to be replaced with an ifup hook in next patch.
--- package/initscripts/init.d/S40network | 29 ----------------------------- 1 file changed, 29 deletions(-)
package/initscripts/init.d/S40network +0 -29
@@ -6,37 +6,8 @@ # Debian ifupdown needs the /run/network lock directory mkdir -p /run/network -# In case we have a slow-to-appear interface (e.g. eth-over-USB), -# and we need to configure it, wait until it appears, but not too -# long either. WAIT_DELAY is in seconds. -WAIT_DELAY=15 - -wait_for_interfaces() { - IFACES=$(awk '/^auto/ { print $2 }' /etc/network/interfaces) - [ -n "$IFACES" ] || return - - printf "Waiting for network interfaces to appear" - - for i in $(seq $WAIT_DELAY); do - for IFACE in $IFACES; do - if [ ! -e "/sys/class/net/$IFACE" ]; then - printf "." - sleep 1 - continue 2 - fi - done - - printf " ok\n"; return - done - - printf " timeout\n" - exit 1 -} - case "$1" in start) - wait_for_interfaces - echo "Starting network..." /sbin/ifup -a ;;
Signature · 1 line
2.1.4
PATCH 2/3 skeleton: optionally wait for network interfaces to appear
In reply to Jérôme PouillerThis patch has same purpose than 49964858f45d2243c513e6d362e992ad89ec7a45:
On some machines, the network interface is slow to appear. For example, on the Raspberry Pi, the network interface eth0 is an ethernet-over-USB, and our standard boot process is too fast, so our network startup script is called before the USB bus is compeltely enumerated, thus it can't configure eth0.
Closes #8116.
However, it use an optionnal ifupdown hook instead of an initscript.
--- system/skeleton/etc/network/if-pre-up.d/wait_iface | 28 ++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100755 system/skeleton/etc/network/if-pre-up.d/wait_iface
system/skeleton/etc/network/if-pre-up.d/wait_iface new file +28 -0
@@ -0,0 +1,28 @@ +#!/bin/sh + +# In case we have a slow-to-appear interface (e.g. eth-over-USB), +# and we need to configure it, wait until it appears, but not too +# long either. IF_WAIT_DELAY is in seconds. + +if [ "${IF_WAIT_DELAY}" ]; then + + printf "Waiting for interface %s to appear" "${IFACE}" + while [ ${IF_WAIT_DELAY} -gt 0 ]; do + + if [ -e "/sys/class/net/${IFACE}" ]; then + + printf " yes\n" + exit 0 + + fi + sleep 1 + printf "." + + : $((IF_WAIT_DELAY -= 1)) + + done + printf " no.\n" + exit 1 + +fi +
Signature · 1 line
2.1.4
PATCH 2/3 skeleton: optionally wait for network interfaces to appear
J?r?me, All,
On 2015-10-28 16:59 +0100, J?r?me Pouiller spake thusly:
Quoted 24 lines
This patch has same purpose than
49964858f45d2243c513e6d362e992ad89ec7a45:On some machines, the network interface is slow to appear. For example, on the Raspberry Pi, the network interface eth0 is an ethernet-over-USB, and our standard boot process is too fast, so our network startup script is called before the USB bus is compeltely enumerated, thus it can't configure eth0.
Closes #8116.
However, it use an optionnal ifupdown hook instead of an initscript.
Signed-off-by J?r?me Pouiller <[email protected]>--- system/skeleton/etc/network/if-pre-up.d/wait_iface | 28 ++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100755 system/skeleton/etc/network/if-pre-up.d/wait_ifacesystem/skeleton/etc/network/if-pre-up.d/wait_iface new file +0
-0
system/skeleton/etc/network/if-pre-up.d/wait_iface line 8
Quoted 8 lines
system/skeleton/etc/network/if-pre-up.d/wait_iface new file +8
-0@@ -0,0 +1,28 @@ +#!/bin/sh + +# In case we have a slow-to-appear interface (e.g. eth-over-USB), +# and we need to configure it, wait until it appears, but not too +# long either. IF_WAIT_DELAY is in seconds. + +if [ "${IF_WAIT_DELAY}" ]; then +
Please drop the empty lines.
Also, I would have preferred patches 2 & 3 to be folded into a single patch. I don't really understand how it all works:
- does the busybox ifup-down and full-fledged ifup-down support wait-delay?
- I looked at man 5 interfaces, and there is no mention of wait-delay,
- I don't see how 'wait-delay' translates to 'wait_iface'
- I guess 'wait-delay' is made an environment variable IF_WAIT_DELAY before the script is run, but I'd have preferred explanations rather than having to guess.
Care to shed some light, please?
Otherwise, the idea looks fine to me. Thanks! :-)
Regards,
Yann E. MORIN.
Quoted 23 lines
system/skeleton/etc/network/if-pre-up.d/wait_iface new file +20
-0+ printf "Waiting for interface %s to appear" "${IFACE}" + while [ ${IF_WAIT_DELAY} -gt 0 ]; do + + if [ -e "/sys/class/net/${IFACE}" ]; then + + printf " yes\n" + exit 0 + + fi + sleep 1 + printf "." + + : $((IF_WAIT_DELAY -= 1)) + + done + printf " no.\n" + exit 1 + +fi +Signature · 1 line
2.1.4
Signature · 6 lines
.-----------------.--------------------.------------------.--------------------. | Yann E. MORIN | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: | | +33 662 376 056 | Software Designer | \ / CAMPAIGN | ___ | | +33 223 225 172 `------------.-------: X AGAINST | \e/ There is no | | http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL | v conspiracy. | '------------------------------^-------^------------------^--------------------'
PATCH 2/3 skeleton: optionally wait for network interfaces to appear
Hello Yann,
Quoted 3 lines · On Wednesday 28 October 2015 18:46:53 Yann E. MORIN wrote:
J?r?me, All,
On 2015-10-28 16:59 +0100, J?r?me Pouiller spake thusly:
[...]
Quoted 1 line
Please drop the empty lines.
There were empty lines in original patch ;-).
Quoted 2 lines
Also, I would have preferred patches 2 & 3 to be folded into a single patch.
ok.
Quoted 4 lines
I don't really understand how it all works:
- does the busybox ifup-down and full-fledged ifup-down support wait-delay?
Yes, both.
Quoted 2 lines
- I looked at man 5 interfaces, and there is no mention of
wait-delay,
I have found documentation related to if-*.d scripts in section called "IFACE OPTIONS" of interfaces(5) of my debian.
Quoted 1 line
- I don't see how 'wait-delay' translates to '
wait_iface'
From interfaces(5):
"Additionally, all options given in an interface definition stanza are
exported to the environment in upper case with "IF_" prepended and with hyphens converted to underscores and non-alphanumeric characters discarded."
Quoted 5 lines
- I guess 'wait-delay' is made an environment variable
IF_WAIT_DELAY
before the script is run, but I'd have preferred explanations rather than having to guess.Care to shed some light, please?
Regards,
Signature · 3 lines
J?r?me Pouiller, Sysmic Embedded Linux specialist http://www.sysmic.fr
PATCH 2/3 skeleton: optionally wait for network interfaces to appear
J?r?me, All,
On 2015-10-28 21:21 +0100, J?r?me Pouiller spake thusly:
Quoted 5 lines · On Wednesday 28 October 2015 18:46:53 Yann E. MORIN wrote:
Quoted 1 line
On 2015-10-28 16:59 +0100, J?r?me Pouiller spake thusly:
[...]
Quoted 1 line
Please drop the empty lines.
There were empty lines in original patch ;-).
OK, I see. ;-)
Still, please drop them next time, please.
[--SNIP--]
Quoted 6 lines
Quoted 2 lines
- I looked at man 5 interfaces, and there is no mention of
wait-delay,I have found documentation related to if-*.d scripts in section called "IFACE OPTIONS" of interfaces(5) of my debian.
Quoted 8 lines
Quoted 1 line
- I don't see how 'wait-delay' translates to '
wait_iface'From interfaces(5):
"Additionally, all options given in an interface definition stanza are
exported to the environment in upper case with "IF_" prepended and with hyphens converted to underscores and non-alphanumeric characters discarded."
OK, thanks for the explanations. So there is no relation between the 'stanza' name and the script name, right?
Also, I read this in man 5 interfaces;
When ifupdown is being called with the --all option, before doing anything to interfaces, if [sic] calls all the hook scripts (pre-up or down) with IFACE set to "--all", LOGICAL set to the current value of --allow parameter (or "auto" if it's not set), ADDRFAM="meta" and METHOD="none". After all the interfaces have been brought up or taken down, the appropriate scripts (up or post-down) are executed.
Since S40network calls 'ifup -a' and you added a pre-up script, I guess it should filter out the '--all' interface and exit early in that case.
Regards,
Yann E. MORIN.
Signature · 6 lines
.-----------------.--------------------.------------------.--------------------. | Yann E. MORIN | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: | | +33 662 376 056 | Software Designer | \ / CAMPAIGN | ___ | | +33 223 225 172 `------------.-------: X AGAINST | \e/ There is no | | http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL | v conspiracy. | '------------------------------^-------^------------------^--------------------'
PATCH 2/3 skeleton: optionally wait for network interfaces to appear
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"Yann" == Yann E MORIN <[email protected]> writes:
Hi,
Quoted 11 lines
Also, I read this in man 5 interfaces;
When ifupdown is being called with the --all option, before doing anything to interfaces, if [sic] calls all the hook scripts (pre-up or down) with IFACE set to "--all", LOGICAL set to the current value of --allow parameter (or "auto" if it's not set), ADDRFAM="meta" and METHOD="none". After all the interfaces have been brought up or taken down, the appropriate scripts (up or post-down) are executed.
Since S40network calls 'ifup -a' and you added a pre-up script, I guess it should filter out the '--all' interface and exit early in that case.
As far as I can see from the busybox implementation atleast, -a (all) only causes it to run ifup/ifdown (with IFACE set to the interface name) for each interface listed as auto, so it doesn't do the "--all" thing, but the Debian variant does.
Signature · 2 lines
Venlig hilsen, Peter Korsgaard
PATCH 2/3 skeleton: optionally wait for network interfaces to appear
Peter, All,
On 2015-10-28 22:51 +0100, Peter Korsgaard spake thusly:
Quoted 10 lines
Quoted 9 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"Yann" == Yann E MORIN <[email protected]> writes:
Also, I read this in man 5 interfaces;
When ifupdown is being called with the --all option, before doing anything to interfaces, if [sic] calls all the hook scripts (pre-up or down) with IFACE set to "--all", LOGICAL set to the current value of --allow parameter (or "auto" if it's not set), ADDRFAM="meta" and METHOD="none". After all the interfaces have been brought up or taken down, the appropriate scripts (up or post-down) are executed.
Quoted 7 lines
Quoted 2 lines
Since S40network calls 'ifup -a' and you added a pre-up script, I guess it should filter out the '--all' interface and exit early in that case.
As far as I can see from the busybox implementation atleast, -a (all) only causes it to run ifup/ifdown (with IFACE set to the interface name) for each interface listed as auto, so it doesn't do the "--all" thing, but the Debian variant does.
Since we already have the option to use the full-fledged ifup-down, we should support the case where IFACE=--all in the script.
Regards,
Yann E. MORIN.
Signature · 6 lines
.-----------------.--------------------.------------------.--------------------. | Yann E. MORIN | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: | | +33 662 376 056 | Software Designer | \ / CAMPAIGN | ___ | | +33 223 225 172 `------------.-------: X AGAINST | \e/ There is no | | http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL | v conspiracy. | '------------------------------^-------^------------------^--------------------'
PATCH 2/3 skeleton: optionally wait for network interfaces to appear
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"Yann" == Yann E MORIN <[email protected]> writes:
Hi,
Quoted 7 lines
Quoted 4 lines
As far as I can see from the busybox implementation atleast, -a (all) only causes it to run ifup/ifdown (with IFACE set to the interface name) for each interface listed as auto, so it doesn't do the "--all" thing, but the Debian variant does.
Since we already have the option to use the full-fledged ifup-down, we should support the case where IFACE=--all in the script.
Yes, agreed - My comment was for information only.
Signature · 2 lines
Venlig hilsen, Peter Korsgaard
PATCH 2/3 skeleton: optionally wait for network interfaces to appear
In reply to Yann E. MORINQuoted 2 lines · Yann E. MORIN
OK, thanks for the explanations. So there is no relation between the 'stanza' name and the script name, right?
None at all. ifupdown just run-parts /etc/if-$PHASE.d/ and the scripts are responsible for not doing anything when they shouldn't.
Quoted 11 lines
Also, I read this in man 5 interfaces;
When ifupdown is being called with the --all option, before doing anything to interfaces, if [sic] calls all the hook scripts (pre-up or down) with IFACE set to "--all", LOGICAL set to the current value of --allow parameter (or "auto" if it's not set), ADDRFAM="meta" and METHOD="none". After all the interfaces have been brought up or taken down, the appropriate scripts (up or post-down) are executed.
Since S40network calls 'ifup -a' and you added a pre-up script, I guess it should filter out the '--all' interface and exit early in that case.
When run in this case, it will have no IF_WAIT_DELAY variable, so the script will not do anything.
PATCH 2/3 skeleton: optionally wait for network interfaces to appear
In reply to Jérôme PouillerQuoted 24 lines · J?r?me Pouiller
This patch has same purpose than
49964858f45d2243c513e6d362e992ad89ec7a45:On some machines, the network interface is slow to appear. For example, on the Raspberry Pi, the network interface eth0 is an ethernet-over-USB, and our standard boot process is too fast, so our network startup script is called before the USB bus is compeltely enumerated, thus it can't configure eth0.
Closes #8116.
However, it use an optionnal ifupdown hook instead of an initscript.
Signed-off-by J?r?me Pouiller <[email protected]>--- system/skeleton/etc/network/if-pre-up.d/wait_iface | 28 ++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100755 system/skeleton/etc/network/if-pre-up.d/wait_ifacesystem/skeleton/etc/network/if-pre-up.d/wait_iface new file +0
-0
system/skeleton/etc/network/if-pre-up.d/wait_iface line 9
Quoted 9 lines
system/skeleton/etc/network/if-pre-up.d/wait_iface new file +9
-0@@ -0,0 +1,28 @@ +#!/bin/sh + +# In case we have a slow-to-appear interface (e.g. eth-over-USB), +# and we need to configure it, wait until it appears, but not too +# long either. IF_WAIT_DELAY is in seconds. + +if [ "${IF_WAIT_DELAY}" ]; then + + printf "Waiting for interface %s to appear" "${IFACE}"
I think we shouldn't print this scary message when the interface already exist in the first place... I was suggesting to only do it if VERBOSITY=1 but busybox does not support that.
system/skeleton/etc/network/if-pre-up.d/wait_iface line 14
Quoted 5 lines
system/skeleton/etc/network/if-pre-up.d/wait_iface new file +5
-0+ while [ ${IF_WAIT_DELAY} -gt 0 ]; do + + if [ -e "/sys/class/net/${IFACE}" ]; then + + printf " yes\n"
So this prints:
"Waiting for interface dummy0 to appear..... yes" or
"Waiting for interface dummy0 to appear............... no"
We should maybe just print a new line on success and an explicit error message on failure.
Quoted 15 lines
system/skeleton/etc/network/if-pre-up.d/wait_iface new file +14
-0+ exit 0 + + fi + sleep 1 + printf "." + + : $((IF_WAIT_DELAY -= 1)) + + done + printf " no.\n" + exit 1 + +fi +
PATCH 3/3 skeleton: wait interface to appear if dhcp is enabled
In reply to Jérôme Pouillerwait-delay hook is enabled only if wait-delay property appears in /etc/network/interfaces. This patch enable it automaticaly when interface is configured through DHCP at bootup. However, if user choose to write /etc/network/interface himself, he have to explicitly set wait-delay.
--- package/skeleton/skeleton.mk | 1 + 1 file changed, 1 insertion(+)
package/skeleton/skeleton.mk +1 -0
@@ -89,6 +89,7 @@ define SET_NETWORK_DHCP echo ; \ echo "auto $(NETWORK_DHCP_IFACE)"; \ echo "iface $(NETWORK_DHCP_IFACE) inet dhcp"; \ + echo " wait-delay 15"; \ ) >> $(TARGET_DIR)/etc/network/interfaces endef endif
Signature · 1 line
2.1.4