/[vps]/baselayout-vserver/branches/baselayout-1_12/net-scripts/net.modules.d/netplugd
Gentoo

Contents of /baselayout-vserver/branches/baselayout-1_12/net-scripts/net.modules.d/netplugd

Parent Directory Parent Directory | Revision Log Revision Log


Revision 252 - (show annotations) (download)
Thu Feb 23 13:39:22 2006 UTC (12 years, 6 months ago) by phreak
File size: 2961 byte(s)
Merging baselayout r1924
1 #!/bin/bash
2 # Copyright (c) 2004-2005 Gentoo Foundation
3 # Distributed under the terms of the GNU General Public License v2
4
5 # Contributed by Roy Marples (uberlord@gentoo.org)
6
7 # void netplugd_depend(void)
8 #
9 # Sets up the dependancies for the module
10 netplugd_depend() {
11 after macnet rename
12 before interface
13 provide plug
14 functions interface_exists interface_get_mac_address
15 }
16
17 # bool netplugd_check_installed(void)
18 #
19 # Returns 0 if netplug is installed, otherwise 1
20 netplugd_check_installed() {
21 if [[ ! -x /sbin/netplugd ]]; then
22 ${1:-false} && eerror "For netplug support, emerge sys-apps/netplug"
23 return 1
24 fi
25 return 0
26 }
27
28 # bool netplugd_pre_start(char *interface)
29 #
30 # Start netplug on an interface
31 netplugd_pre_start() {
32 local iface="$1" timeout
33 local pidfile="/var/run/netplugd.${iface}.pid"
34
35 # We don't start netplug if we're being called from the background
36 ${IN_BACKGROUND} && return 0
37
38 interface_exists "${iface}" || return 0
39
40 # We need a valid MAC address
41 # It's a basic test to ensure it's not a virtual interface
42 local mac=$(interface_get_mac_address "${iface}")
43 if [[ -z ${mac} ]]; then
44 vewarn "netplug only works on interfaces with a valid MAC address"
45 return 0
46 fi
47
48 # We don't work on bonded, bridges, tun/tap, vlan or wireless
49 for f in bonding bridge tuntap vlan wireless ; do
50 if is_function "${f}_exists" ; then
51 if ${f}_exists "${iface}" ; then
52 veinfo "netplug does not work with ${f}"
53 return 0
54 fi
55 fi
56 done
57
58 ebegin "Starting netplug on ${iface}"
59
60 # We need the interface up for netplug to listen to netlink events
61 interface_up "${iface}"
62
63 # Mark the us as inactive so netplug can restart us
64 mark_service_inactive "net.${iface}"
65
66 # Start netplug
67 start-stop-daemon --start --exec /sbin/netplugd \
68 --pidfile "${pidfile}" \
69 -- -i "${iface}" -P -p "${pidfile}" -c /dev/null
70 eend "$?" || return 1
71
72 eindent
73
74 timeout="plug_timeout_${ifvar}"
75 timeout="${!timeout:--1}"
76 if [[ ${timeout} == "0" ]]; then
77 ewarn "WARNING: infinite timeout set for ${iface} to come up"
78 elif [[ ${timeout} -lt 0 ]]; then
79 einfo "Backgrounding ..."
80 exit 0
81 fi
82
83 veinfo "Waiting for ${iface} to be marked as started"
84
85 local i=0
86 while true ; do
87 if service_started "net.${iface}"; then
88 local addr=$( interface_get_address "${iface}" )
89 einfo "${iface} configured with address ${addr}"
90 exit 0
91 fi
92 sleep 1
93 [[ ${timeout} == "0" ]] && continue
94 (( i++ ))
95 [[ ${i} == "${timeout}" || ${i} -gt "${timeout}" ]] && break
96 done
97
98 eend 1 "Failed to configure ${iface} in the background"
99 exit 0
100 }
101
102 # bool netplugd_stop(char *iface)
103 #
104 # Stops netplug on an interface
105 # Returns 0 (true) when successful, non-zero otherwise
106 netplugd_stop() {
107 ${IN_BACKGROUND} && return 0
108 local iface="$1"
109 local pidfile="/var/run/netplugd.${iface}.pid"
110
111 [[ ! -e ${pidfile} ]] && return 0
112
113 ebegin "Stopping netplug on ${iface}"
114 start-stop-daemon --stop --exec /sbin/netplugd \
115 --pidfile "${pidfile}"
116 eend $?
117 }
118
119 # vim:ts=4

  ViewVC Help
Powered by ViewVC 1.1.20