Skip to content
This repository was archived by the owner on Jan 16, 2024. It is now read-only.

Commit 87bb019

Browse files
authored
M #: Ensure proper network restart for alpine 3.16+ (#296)
1 parent 0b9f88f commit 87bb019

1 file changed

Lines changed: 17 additions & 13 deletions

File tree

src/etc/one-context.d/loc-10-network.d/netcfg-interfaces

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,7 @@ stop_network()
4646
alpine)
4747
service networking stop || true
4848

49-
# took from find_ifaces in the networking service
50-
_ifaces=$(\
51-
awk '$1 == "auto" {
52-
for (i = 2; i <= NF; i = i + 1) printf("%s ", $i)
53-
}' /etc/network/interfaces)
54-
55-
for _iface in $_ifaces; do
49+
for _iface in $(get_interfaces); do
5650
if [ "${_iface}" != 'lo' ]; then
5751
/sbin/ip link set dev "${_iface}" down || true
5852
/sbin/ip addr flush dev "${_iface}" || true
@@ -64,9 +58,7 @@ stop_network()
6458
return 0
6559
fi
6660

67-
_ifaces=$(/sbin/ifquery --list -a)
68-
69-
for _iface in $_ifaces; do
61+
for _iface in $(get_interfaces); do
7062
if [ "${_iface}" != 'lo' ] ; then
7163
/sbin/ifdown "${_iface}"
7264
/sbin/ip link set dev "${_iface}" down || true
@@ -85,16 +77,23 @@ start_network()
8577
case "${os_id}" in
8678
alpine)
8779
service networking start
80+
81+
# alpine 3.16+ might fail to set the interface configuration of an interface that was removed
82+
# from /etc/network/interfaces. This results in the interface having a definition
83+
# in the configuration file, but no actual interface configuration.
84+
85+
for _iface in $(get_interfaces); do
86+
ip link show "$_iface" | grep -q 'state DOWN' && service networking restart && break
87+
done
88+
8889
;;
8990
debian|ubuntu|devuan)
9091
if [ -f "/usr/sbin/ifreload" ] ; then
9192
/usr/sbin/ifreload -a
9293
return 0
9394
fi
9495

95-
_ifaces=$(/sbin/ifquery --list -a)
96-
97-
for _iface in $_ifaces; do
96+
for _iface in $(get_interfaces); do
9897
/sbin/ifup "${_iface}"
9998
done
10099
;;
@@ -424,3 +423,8 @@ EOT
424423
;;
425424
esac
426425
}
426+
427+
# took from find_ifaces in the networking service
428+
get_interfaces() {
429+
/sbin/ifquery --list -a
430+
}

0 commit comments

Comments
 (0)