ifupdown-ng/dist/openrc/networking.initd

71 lines
1.3 KiB
Text
Raw Normal View History

2020-10-14 08:32:05 +00:00
#!/sbin/openrc-run
: ${cfgfile:="/etc/network/interfaces"}
ifstate=/run/ifstate
single_iface="${RC_SVCNAME#*.}"
if [ "$single_iface" = "$RC_SVCNAME" ]; then
single_iface=
fi
depend() {
need localmount
want dev-settle
after bootmisc hwdrivers modules
provide net
keyword -jail -prefix -vserver -docker
}
# find interfaces we want to start
find_ifaces() {
if [ -n "$single_iface" ]; then
echo $single_iface
else
ifquery -L -i "$cfgfile"
2020-10-14 08:32:05 +00:00
fi
}
# return the list of interfaces we should try stop
find_running_ifaces() {
if [ -n "$single_iface" ]; then
echo $single_iface
else
ifquery -r -i "$cfgfile" -S "$ifstate"
2020-10-14 08:32:05 +00:00
fi
}
start() {
local iface= ret=1
ebegin "Starting networking"
eindent
for iface in $(find_ifaces); do
local r=0
ebegin "$iface"
if ! ifup -i "$cfgfile" -S "$ifstate" $iface >/dev/null; then
ifdown -f -i "$cfgfile" -S "$ifstate" $iface >/dev/null 2>&1
2020-10-14 08:32:05 +00:00
r=1
fi
# atleast one interface needs to be started for action
# to be success
eend $r && ret=0
done
eoutdent
return $ret
}
stop() {
local iface=
# Don't stop the network at shutdown.
yesno ${keep_network:-YES} && yesno $RC_GOINGDOWN && return 0
ebegin "Stopping networking"
eindent
for iface in $(find_running_ifaces); do
ebegin "$iface"
ifdown -i "$cfgfile" -S "$ifstate" -f $iface >/dev/null
2020-10-14 08:32:05 +00:00
eend $?
done
eoutdent
return 0
}