/[vps]/baselayout-vserver/trunk/lib/rcscripts/net.modules.d/netplug
Gentoo

Contents of /baselayout-vserver/trunk/lib/rcscripts/net.modules.d/netplug

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3 - (show annotations) (download)
Sat Sep 3 16:10:27 2005 UTC (9 years, 3 months ago) by hollow
File size: 3018 byte(s)
import initial baselayout sources (1.12.0_pre8)
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 # char* netplug_provides(void)
8 #
9 # Returns a string to change module definition for starting up
10 netplug_provides() {
11 echo "netplug"
12 }
13
14 # void netplug_depend(void)
15 #
16 # Sets up the dependancies for the module
17 netplug_depend() {
18 after macnet
19 before interface
20 }
21
22 # bool netplug_check_installed(void)
23 #
24 # Returns 0 if netplug is installed, otherwise 1
25 netplug_check_installed() {
26 if [[ ! -x /sbin/netplugd ]]; then
27 ${1:-false} && eerror "For netplug support, emerge sys-apps/netplug"
28 return 1
29 fi
30 return 0
31 }
32
33 # bool netplug_check_depends(void)
34 #
35 # Checks to see if we have the needed functions
36 netplug_check_depends() {
37 local f
38
39 for f in interface_exists; do
40 [[ $( type -t "${f}" ) == "function" ]] && continue
41 eerror "netplug: missing required function ${f}\n"
42 return 1
43 done
44
45 return 0
46 }
47
48 # bool netplug_pre_start(char *interface)
49 #
50 # Start netplug on an interface
51 netplug_pre_start() {
52 local iface="$1" timeout i
53 local pidfile="/var/run/netplug.${iface}.pid"
54
55 # We don't start netplug if we're being called from the background
56 ${IN_BACKGROUND} && return 0
57
58 # We need a valid MAC address
59 # It's a basic test to ensure it's not a virtual interface
60 local mac=$(interface_get_mac_address "${iface}")
61 if [[ -z ${mac} ]]; then
62 vewarn "netplug only works on interfaces with a valid MAC address"
63 return 0
64 fi
65
66 # We don't work on wirelesss interfaces
67 if [[ $(type -t wireless_check_extensions) == "function" ]]; then
68 if wireless_check_extensions "${iface}"; then
69 veinfo "netplug does not work on wireless interfaces"
70 return 0
71 fi
72 fi
73
74 ebegin "Starting netplug on ${iface}"
75
76 # We need the interface up for netplug to listen to netlink events
77 interface_up "${iface}"
78
79 # Mark the us as inactive so netplug can restart us
80 mark_service_inactive "net.${iface}"
81
82 # Start netplug
83 start-stop-daemon --start --exec /sbin/netplugd \
84 --pidfile "${pidfile}" \
85 -- -i "${iface}" -P -p "${pidfile}" -c /dev/null
86 eend "$?" || return 1
87
88 eindent
89 veinfo "Waiting for ${iface} to be marked as started"
90
91 eval timeout=\"\$\{plug_timeout_${ifvar}\:-10}\"
92 [[ ${timeout} == "0" ]] \
93 && vewarn "WARNING: infinite timeout set for ${iface} to come up"
94
95 i=0
96 while true ; do
97 if service_started "net.${iface}"; then
98 local addr=$( interface_get_address "${iface}" )
99 einfo "${iface} configured with address ${addr}"
100 exit 0
101 fi
102 sleep 1
103 (( i++ ))
104 [[ ${i} == "${timeout}" || ${i} -gt "${timeout}" ]] && break
105 done
106
107 eend 1 "Failed to configure ${iface} in the background"
108 exit 0
109 }
110
111 # bool netplug_post_stop(char *iface)
112 #
113 # Stops netplug on an interface
114 # Returns 0 (true) when successful, non-zero otherwise
115 netplug_post_stop() {
116 ${IN_BACKGROUND} && return 0
117 ebegin "Stopping netplug on $1"
118 start-stop-daemon --stop --exec /sbin/netplugd \
119 --pidfile "/var/run/netplug.$1.pid"
120 eend $?
121 }
122
123 # vim:ts=4

  ViewVC Help
Powered by ViewVC 1.1.20