openrc/net.Linux/netplugd.sh

95 lines
2.1 KiB
Bash
Raw Normal View History

# Copyright 2007-2008 Roy Marples <roy@marples.name>
# All rights reserved. Released under the 2-clause BSD license.
_config_vars="$_config_vars plug_timeout"
netplugd_depend()
{
program start /sbin/netplugd
after macnet rename
before interface
provide plug
2007-12-28 20:53:43 +05:30
# Prefer ifplugd
before ifplugd
}
netplugd_pre_start()
{
local pidfile="/var/run/netplugd-${IFACE}.pid" timeout=
# We don't start netplug if we're being called from the background
2007-11-22 18:58:14 +05:30
yesno ${IN_BACKGROUND} && return 0
_exists || return 0
# We need a valid MAC address
# It's a basic test to ensure it's not a virtual interface
2007-11-28 21:15:03 +05:30
if ! _get_mac_address >/dev/null 2>&1; then
vewarn "netplug only works on interfaces with a valid MAC address"
return 0
fi
# We don't work on bonded, bridges, tun/tap, vlan or wireless
2007-11-28 21:15:03 +05:30
for f in bond bridge tuntap vlan wireless; do
if type "_is_${f}" >/dev/null 2>&1; then
if _is_${f}; then
veinfo "netplug does not work with" "${f}"
return 0
fi
fi
done
ebegin "Starting netplug on" "${IFACE}"
# Mark the us as inactive so netplug can restart us
2007-12-18 23:29:29 +05:30
mark_service_inactive
# Start netplug
start-stop-daemon --start --exec /sbin/netplugd \
--pidfile "${pidfile}" \
-- -i "${IFACE}" -P -p "${pidfile}" -c /dev/null
eend "$?" || return 1
eindent
eval timeout=\$plug_timeout_${IFVAR}
[ -z "${timeout}" ] && timeout=-1
2007-11-28 21:15:03 +05:30
if [ ${timeout} -eq 0 ]; then
ewarn "WARNING: infinite timeout set for ${IFACE} to come up"
elif [ ${timeout} -lt 0 ]; then
einfo "Backgrounding ..."
exit 1
fi
2007-11-28 21:15:03 +05:30
veinfo "Waiting for ${IFACE} to be marked as started"
local i=0
2007-11-28 21:15:03 +05:30
while true; do
2007-12-18 23:29:29 +05:30
if service_started; then
_show_address
exit 0
fi
sleep 1
2007-11-28 21:15:03 +05:30
[ ${timeout} -eq 0 ] && continue
i=$((${i} + 1))
[ ${i} -ge ${timeout} ] && break
done
2007-11-28 21:15:03 +05:30
eend 1 "Failed to configure ${IFACE} in the background"
exit 1
}
netplugd_stop()
{
2007-11-22 18:58:14 +05:30
yesno ${IN_BACKGROUND} && return 0
local pidfile="/var/run/netplugd-${IFACE}.pid"
[ ! -e "${pidfile}" ] && return 0
ebegin "Stopping netplug on" "${IFACE}"
start-stop-daemon --stop --quiet --exec /sbin/netplugd \
--pidfile "${pidfile}"
eend $?
}