Changeset 8462 in vbox
- Timestamp:
- Apr 29, 2008 1:14:07 PM (17 years ago)
- svn:sync-xref-src-repo-rev:
- 30325
- Location:
- trunk/debian
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/debian/vboxdrv.init.in
r8171 r8462 6 6 7 7 # 8 # Copyright (C) 2006-2007 Sun Microsystems, Inc. GmbH8 # Copyright (C) 2006-2007 Sun Microsystems, Inc. 9 9 # 10 10 # This file is part of VirtualBox Open Source Edition (OSE), as -
trunk/debian/vboxnet.init.in
r8171 r8462 1 1 #! /bin/sh 2 #3 2 # Sun xVM VirtualBox 4 3 # Linux static host networking interface initialization … … 6 5 7 6 # 8 # Copyright (C) 2007 Sun Microsystems, Inc. GmbH7 # Copyright (C) 2007 Sun Microsystems, Inc. 9 8 # 10 9 # This file is part of VirtualBox Open Source Edition (OSE), as … … 26 25 # Default-Start: 3 5 27 26 # Default-Stop: 28 # Short-Description:VirtualBox permanent host networking setup27 # Description: VirtualBox permanent host networking setup 29 28 ### END INIT INFO 30 29 31 PATH= $PATH:/bin:/sbin:/usr/sbin30 PATH=/sbin:/bin:/usr/sbin:/usr/bin:$PATH 32 31 CONFIG="/etc/vbox/interfaces" 33 32 VARDIR="/var/run/VirtualBox" 34 33 VARFILE="/var/run/VirtualBox/vboxnet" 35 34 TAPDEV="/dev/net/tun" 36 NOLSB=%LSB% 37 38 if [ -z "$NOLSB" -a -f /lib/lsb/init-functions ]; then 39 . /lib/lsb/init-functions 35 NOLSB=%NOLSB% 36 37 [ -f /lib/lsb/init-functions ] || NOLSB=yes 38 39 if [ -n "$NOLSB" ]; then 40 if [ -f /etc/redhat-release ]; then 41 system=redhat 42 elif [ -f /etc/SuSE-release ]; then 43 system=suse 44 elif [ -f /etc/gentoo-release ]; then 45 system=gentoo 46 fi 47 fi 48 49 if [ -z "$NOLSB" ]; then 50 . /lib/lsb/init-functions 51 fail_msg() { 52 echo "" 53 log_failure_msg "$1" 54 } 55 succ_msg() { 56 log_success_msg " done." 57 } 58 begin_msg() { 59 log_daemon_msg "$@" 60 } 40 61 else 41 log_action_begin_msg() 42 { 43 echo -n "$@..." 44 } 45 log_action_end_msg() 46 { 47 if [ -z "${2:-}" ]; then 48 end="." 62 if [ "$system" = "redhat" ]; then 63 . /etc/init.d/functions 64 fail_msg() { 65 echo_failure 66 echo 67 echo " ($1)" 68 } 69 succ_msg() { 70 echo_success 71 echo 72 } 73 elif [ "$system" = "suse" ]; then 74 . /etc/rc.status 75 fail_msg() { 76 rc_failed 1 77 rc_status -v 78 echo " ($1)" 79 } 80 succ_msg() { 81 rc_reset 82 rc_status -v 83 } 84 elif [ "$system" = "gentoo" ]; then 85 . /sbin/functions.sh 86 fail_msg() { 87 eerror "$1" 88 } 89 succ_msg() { 90 eend "$?" 91 } 92 begin_msg() { 93 ebegin "$1" 94 } 95 if [ "`which $0`" = "/sbin/rc" ]; then 96 shift 97 fi 49 98 else 50 end=" ($2)." 51 fi 52 if [ $1 -eq 0 ]; then 53 echo "done${end}" 54 else 55 echo "failed${end}" 56 fi 57 } 58 log_success_msg() 59 { 60 echo "$@" 61 } 62 log_failure_msg() 63 { 64 echo "$@" 65 } 99 fail_msg() { 100 echo " ...failed!" 101 echo " ($1)" 102 } 103 succ_msg() { 104 echo " ...done." 105 } 106 fi 107 if [ "$system" != "gentoo" ]; then 108 begin_msg() { 109 [ -z "${1:-}" ] && return 1 110 if [ -z "${2:-}" ]; then 111 echo -n "$1" 112 else 113 echo -n "$1: $2" 114 fi 115 } 116 fi 66 117 fi 67 118 68 119 failure() 69 120 { 70 log_action_end_msg 1 "$1" 71 exit 0 121 fail_msg "$1" 122 # never return with exit code != 0 123 exit 0 72 124 } 73 125 74 126 running() 75 127 { 76 test -f "$VARFILE" 77 } 78 79 valid_ifname() 80 { 81 if expr match "$1" "vbox[0-9][0-9]*$" > /dev/null 2>&1; then 82 return 0 83 else 84 return 1 85 fi 128 test -f "$VARFILE" 86 129 } 87 130 … … 90 133 # /var/run/VirtualBox/vboxnet. If this file already exists, assume that the 91 134 # script has already been started and do nothing. 92 start_network() { 93 log_action_begin_msg "Starting VirtualBox host networking" 135 start_network() 136 { 137 begin_msg "Starting VirtualBox host networking" 94 138 # If the service is already running, return successfully. 95 139 if [ -f "$VARFILE" ]; then 96 log_action_end_msg 0140 succ_msg 97 141 return 0 98 142 fi … … 108 152 # If there is no configuration file, report success 109 153 if [ ! -f "$CONFIG" ]; then 110 log_action_end_msg 0154 succ_msg 111 155 return 0 112 156 fi … … 116 160 fi 117 161 # Fail if we don't have tunctl 118 if ! VBoxTunctl -h 2>&1 | grep -qVBoxTunctl > /dev/null; then162 if ! VBoxTunctl -h 2>&1 | grep VBoxTunctl > /dev/null; then 119 163 failure "VBoxTunctl not found" 120 164 fi … … 122 166 # Make sure that the tun module is loaded (Ubuntu 7.10 needs this) 123 167 modprobe tun > /dev/null 2>&1 124 if ! cat /proc/misc 2>/dev/null | grep tun > /dev/null 125 then 168 if ! cat /proc/misc 2>/dev/null | grep tun > /dev/null; then 126 169 failure "Linux tun/tap subsystem not available" 127 170 fi 171 succ_msg 128 172 # Read the configuration file entries line by line and create the 129 173 # interfaces … … 135 179 # or two non-comment entries, possibly followed by a comment). 136 180 if ((! expr match "$2" "#" > /dev/null) && 137 (test -z "$4" || expr match "$4" "#" > /dev/null) && 138 (valid_ifname "$1")) 139 then 181 (test -z "$4" || expr match "$4" "#" > /dev/null)); then 182 # As the very first thing, try delete the interface. Might already 183 # exist with different configuration. Ignore errors. 184 VBoxTunctl -d $1 > /dev/null 2>&1 185 case $user in 186 +*) 187 group=`echo $2 | cut -c2-` 188 cmd="VBoxTunctl -t $1 -g $group" 189 ;; 190 *) 191 cmd="VBoxTunctl -t $1 -u $2" 192 ;; 193 esac 140 194 # Try to create the interface 141 if VBoxTunctl -t "$1" -u "$2" > /dev/null 2>&1 142 then 195 if $cmd > /dev/null 2>&1; then 143 196 # On SUSE Linux Enterprise Server, the interface does not 144 197 # appear immediately, so we loop trying to bring it up. 145 198 i=1 146 while [ $i -le 10 ] 147 do 199 while [ $i -le 10 ]; do 148 200 ifconfig "$1" up 2> /dev/null 149 if ifconfig | grep "$1" > /dev/null 2>&1 150 then 201 if ifconfig | grep "$1" > /dev/null; then 151 202 # Add the interface to a bridge if one was specified 152 if [ ! -z "$3" ] 153 then 154 if brctl addif "$3" "$1" 2> /dev/null 155 then 156 echo "$1 $2 $3" > "$VARFILE" 203 if [ -n "$3" ]; then 204 if brctl addif "$3" "$1" 2> /dev/null; then 205 echo "$1 $2 $3" >> "$VARFILE" 157 206 else 158 echo "$1 $2" > "$VARFILE"207 echo "$1 $2" >> "$VARFILE" 159 208 echo "Warning - failed to add interface $1 to the bridge $3" 160 209 fi 161 210 else 162 echo "$1 $2" > $VARFILE211 echo "$1 $2" >> "$VARFILE" 163 212 fi 164 213 i=20 … … 168 217 fi 169 218 done 170 if [ $i -ne 20 ] 171 then 219 if [ $i -ne 20 ]; then 172 220 echo "Warning - failed to bring up the interface $1" 173 221 fi … … 176 224 fi 177 225 else 178 echo179 226 echo "Warning - invalid line in $CONFIG:" 180 227 echo " $line" … … 184 231 # Set /dev/net/tun to belong to the group vboxusers if it exists and does 185 232 # yet belong to a group. 186 if ls -g "$TAPDEV" 2>/dev/null | grep -q root; then233 if ls -g "$TAPDEV" 2>/dev/null | grep root > /dev/null; then 187 234 chgrp vboxusers "$TAPDEV" 188 235 chmod 0660 "$TAPDEV" 189 236 fi 190 log_action_end_msg 0191 237 return 0 192 238 } … … 194 240 # Shut down VirtualBox host networking and remove all permanent TAP 195 241 # interfaces. This action will fail if some interfaces could not be removed. 196 stop_network() { 197 log_action_begin_msg "Shutting down VirtualBox host networking" 242 stop_network() 243 { 244 begin_msg "Shutting down VirtualBox host networking" 198 245 # If there is no runtime record file, assume that the service is not 199 246 # running. 200 247 if [ ! -f "$VARFILE" ]; then 201 log_action_end_msg 0248 succ_msg 202 249 return 0 203 250 fi … … 208 255 fi 209 256 # Fail if we don't have tunctl 210 if ! VBoxTunctl -h 2>&1 | grep -qVBoxTunctl > /dev/null; then257 if ! VBoxTunctl -h 2>&1 | grep VBoxTunctl > /dev/null; then 211 258 failure "VBoxTunctl not found" 212 259 fi … … 217 264 set ""$line 218 265 # Remove the interface from a bridge if it is part of one 219 if [ ! -z"$3" ]; then266 if [ -n "$3" ]; then 220 267 brctl delif "$3" "$1" 2> /dev/null 221 268 fi … … 223 270 # possible 224 271 if (! ifconfig "$1" down 2> /dev/null || 225 ! VBoxTunctl -d "$1" > /dev/null 2>&1) 226 then 272 ! VBoxTunctl -d "$1" > /dev/null 2>&1); then 227 273 while read line; do 228 274 set ""$line 229 275 VBoxTunctl -t "$1" -u "$2" > /dev/null 2>&1 230 276 ifconfig "$1" up 2> /dev/null 231 if [ ! -z"$3" ]; then277 if [ -n "$3" ]; then 232 278 brctl addif "$3" "$1" 233 279 fi 234 280 done < "$VARFILE" 235 failure "Removing of interface failed"236 281 fi 237 282 done < "$VARFILE" 238 283 rm -f "$VARFILE" 2> /dev/null 239 log_action_end_msg 0284 succ_msg 240 285 return 0 241 286 } … … 245 290 # removed. It is only intended for exceptional circumstances such as 246 291 # uninstalling VirtualBox. 247 force_stop_network() { 248 log_action_begin_msg "Shutting down VirtualBox host networking" 292 force_stop_network() 293 { 294 begin_msg "Shutting down VirtualBox host networking" 249 295 # If there is no runtime record file, assume that the service is not 250 296 # running. 251 297 if [ ! -f "$VARFILE" ]; then 252 log_action_end_msg 0298 succ_msg 253 299 return 0 254 300 fi … … 259 305 fi 260 306 # Fail if we don't have tunctl 261 if ! VBoxTunctl -h 2>&1 | grep -qVBoxTunctl > /dev/null; then307 if ! VBoxTunctl -h 2>&1 | grep VBoxTunctl > /dev/null; then 262 308 failure "VBoxTunctl not found" 263 309 fi … … 268 314 set ""$line 269 315 # Remove the interface from a bridge if it is part of one 270 if [ ! -z"$3" ]; then316 if [ -n "$3" ]; then 271 317 brctl delif "$3" "$1" 2> /dev/null 272 318 fi … … 276 322 done < "$VARFILE" 277 323 rm -f "$VARFILE" 2> /dev/null 278 log_action_end_msg 0324 succ_msg 279 325 return 0 280 326 } … … 287 333 stop_network 288 334 ;; 289 restart|reload|force-reload) 335 restart|reload) 336 stop_network && start_network 337 ;; 338 force-reload) 290 339 stop_network 291 340 start_network … … 296 345 status) 297 346 if running; then 298 log_success_msg"VirtualBox host networking is loaded."347 echo "VirtualBox host networking is loaded." 299 348 else 300 log_failure_msg"VirtualBox host networking is not loaded."349 echo "VirtualBox host networking is not loaded." 301 350 fi 302 351 ;; … … 306 355 esac 307 356 308 exit 357 exit 0
Note:
See TracChangeset
for help on using the changeset viewer.