2009-05-01 15:11:40 +01:00
|
|
|
# Copyright (c) 2007-2008 Roy Marples <roy@marples.name>
|
2011-06-29 19:46:31 -04:00
|
|
|
# Released under the 2-clause BSD license.
|
2007-11-14 15:22:04 +00:00
|
|
|
|
2007-04-05 11:18:42 +00:00
|
|
|
_config_vars="$_config_vars plug_timeout"
|
|
|
|
|
2008-01-11 15:08:57 +00:00
|
|
|
netplugd_depend()
|
|
|
|
{
|
2007-04-05 11:18:42 +00:00
|
|
|
program start /sbin/netplugd
|
|
|
|
after macnet rename
|
|
|
|
before interface
|
|
|
|
provide plug
|
|
|
|
|
2007-12-28 15:23:43 +00:00
|
|
|
# Prefer ifplugd
|
|
|
|
before ifplugd
|
2007-04-05 11:18:42 +00:00
|
|
|
}
|
|
|
|
|
2008-01-11 15:08:57 +00:00
|
|
|
netplugd_pre_start()
|
|
|
|
{
|
2007-04-05 11:18:42 +00:00
|
|
|
local pidfile="/var/run/netplugd-${IFACE}.pid" timeout=
|
|
|
|
|
|
|
|
# We don't start netplug if we're being called from the background
|
2007-11-22 13:28:14 +00:00
|
|
|
yesno ${IN_BACKGROUND} && return 0
|
2007-04-05 11:18:42 +00:00
|
|
|
|
|
|
|
_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 15:45:03 +00:00
|
|
|
if ! _get_mac_address >/dev/null 2>&1; then
|
2007-04-05 11:18:42 +00:00
|
|
|
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 15:45:03 +00:00
|
|
|
for f in bond bridge tuntap vlan wireless; do
|
|
|
|
if type "_is_${f}" >/dev/null 2>&1; then
|
|
|
|
if _is_${f}; then
|
2007-04-05 11:18:42 +00:00
|
|
|
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 17:59:29 +00:00
|
|
|
mark_service_inactive
|
2007-04-05 11:18:42 +00:00
|
|
|
|
|
|
|
# Start netplug
|
|
|
|
start-stop-daemon --start --exec /sbin/netplugd \
|
|
|
|
--pidfile "${pidfile}" \
|
|
|
|
-- -i "${IFACE}" -P -p "${pidfile}" -c /dev/null
|
|
|
|
eend "$?" || return 1
|
|
|
|
|
|
|
|
eindent
|
|
|
|
|
2011-04-19 17:17:53 +00:00
|
|
|
# IFACE-specific, then global, then default
|
2007-04-05 11:18:42 +00:00
|
|
|
eval timeout=\$plug_timeout_${IFVAR}
|
2011-04-19 17:17:53 +00:00
|
|
|
[ -z "${timeout}" ] && timeout=$plug_timeout
|
2007-04-05 11:18:42 +00:00
|
|
|
[ -z "${timeout}" ] && timeout=-1
|
2007-11-28 15:45:03 +00:00
|
|
|
if [ ${timeout} -eq 0 ]; then
|
|
|
|
ewarn "WARNING: infinite timeout set for ${IFACE} to come up"
|
|
|
|
elif [ ${timeout} -lt 0 ]; then
|
2007-04-05 11:18:42 +00:00
|
|
|
einfo "Backgrounding ..."
|
2011-01-17 04:49:07 -05:00
|
|
|
exit 1
|
2007-04-05 11:18:42 +00:00
|
|
|
fi
|
|
|
|
|
2007-11-28 15:45:03 +00:00
|
|
|
veinfo "Waiting for ${IFACE} to be marked as started"
|
2007-04-05 11:18:42 +00:00
|
|
|
|
|
|
|
local i=0
|
2007-11-28 15:45:03 +00:00
|
|
|
while true; do
|
2007-12-18 17:59:29 +00:00
|
|
|
if service_started; then
|
2007-04-05 11:18:42 +00:00
|
|
|
_show_address
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
sleep 1
|
2007-11-28 15:45:03 +00:00
|
|
|
[ ${timeout} -eq 0 ] && continue
|
2011-11-10 21:46:08 -05:00
|
|
|
: $(( i += 1 ))
|
2007-04-05 11:18:42 +00:00
|
|
|
[ ${i} -ge ${timeout} ] && break
|
|
|
|
done
|
|
|
|
|
2007-11-28 15:45:03 +00:00
|
|
|
eend 1 "Failed to configure ${IFACE} in the background"
|
2007-04-05 11:18:42 +00:00
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2008-01-11 15:08:57 +00:00
|
|
|
netplugd_stop()
|
|
|
|
{
|
2007-11-22 13:28:14 +00:00
|
|
|
yesno ${IN_BACKGROUND} && return 0
|
2007-04-05 11:18:42 +00:00
|
|
|
|
|
|
|
local pidfile="/var/run/netplugd-${IFACE}.pid"
|
|
|
|
[ ! -e "${pidfile}" ] && return 0
|
2011-01-17 04:49:07 -05:00
|
|
|
|
2007-04-05 11:18:42 +00:00
|
|
|
ebegin "Stopping netplug on" "${IFACE}"
|
|
|
|
start-stop-daemon --stop --quiet --exec /sbin/netplugd \
|
|
|
|
--pidfile "${pidfile}"
|
|
|
|
eend $?
|
|
|
|
}
|