]> git.pld-linux.org Git - packages/VirtualBox.git/blob - VirtualBox-vboxnetadp.init
- typo
[packages/VirtualBox.git] / VirtualBox-vboxnetadp.init
1 #!/bin/sh
2 #
3 # virtualbox    VirtualBox virtualizer for x86 hardware
4 #
5 # chkconfig:    345 84 25
6 #
7 # description:  Oracle VirtualBox is a general-purpose full virtualizer for x86 \
8 #               hardware. Targeted at server, desktop and embedded use.
9 #
10 # $Id$
11
12 # Source function library
13 . /etc/rc.d/init.d/functions
14
15 VBOX_DEVICE="/dev/vboxnetctl"
16 VBOX_MODULE="vboxnetadp"
17
18 # Get service config - may override defaults
19 [ -f /etc/sysconfig/virtualbox ] && . /etc/sysconfig/virtualbox
20
21 setup() {
22         modprobe -s $VBOX_MODULE
23         RETVAL=$?
24
25         if [ -d /dev/.udev ] || [ -d /run/udev/rules.d ]; then
26                 return $RETVAL
27         fi
28
29         # set proper $VBOX_DEVICE for systems with static dev
30         show "Setting $VBOX_DEVICE entry"; busy
31         rm -f $VBOX_DEVICE
32         VBOX_MAJOR=$(awk -vdevice="${VBOX_DEVICE#/dev/}" '$2 == device {print $1}' /proc/devices)
33         if [ -n "$VBOX_MAJOR" ]; then
34                 VBOX_MINOR=0
35         else
36                 VBOX_MINOR=$(awk -vdevice="${VBOX_DEVICE#/dev/}" '$2 == device {print $1}' /proc/misc)
37                 if [ -n "$VBOX_MINOR" ]; then
38                         VBOX_MAJOR=$(awk '$2 == "misc" {print $1}' /proc/devices)
39                 fi
40         fi
41
42         if [ -z "$VBOX_MAJOR" ]; then
43                 /sbin/rmmod $VBOX_MODULE
44                 RETVAL=1
45         elif ! mknod -m 0660 $VBOX_DEVICE c $VBOX_MAJOR $VBOX_MINOR; then
46                 RETVAL=$?
47                 rmmod $VBOX_MODNAME
48                 fail
49         elif ! chown root:vbox $VBOX_DEVICE; then
50                 RETVAL=$?
51                 fail
52         else
53                 ok
54         fi
55         return $RETVAL
56 }
57
58 start() {
59         if [ -f /var/lock/subsys/$VBOX_MODULE ]; then
60                 return
61         fi
62
63         setup || exit $?
64         touch /var/lock/subsys/$VBOX_MODULE
65 }
66
67 stop() {
68         # NOTE: rmmod will wait if device is in use, so automatic rmmod probably is not the best idea
69         /sbin/rmmod $VBOX_MODULE
70         rm -f /var/lock/subsys/$VBOX_MODULE
71 }
72
73 condrestart() {
74         if [ -f /var/lock/subsys/$VBOX_MODULE ]; then
75                 stop
76                 start
77         else
78                 RETVAL=$1
79         fi
80 }
81
82 RETVAL=0
83 # See how we were called.
84 case "$1" in
85   start)
86         start
87         ;;
88   stop)
89         stop
90         ;;
91   restart)
92         stop
93         start
94         ;;
95   try-restart)
96         condrestart 0
97         ;;
98   force-reload)
99         condrestart 7
100         ;;
101   setup)
102         setup
103         ;;
104   status)
105         if ! is_module $VBOX_MODULE; then
106                 echo "$VBOX_MODULE module is loaded"
107         else
108                 echo "$VBOX_MODULE module is not loaded"
109                 RETVAL=3
110         fi
111         if [ ! -c $VBOX_DEVICE ]; then
112                 echo "$VBOX_DEVICE does not exist"
113                 RETVAL=3
114         else
115                 echo "$VBOX_DEVICE exists with major/minor $(ls -l $VBOX_DEVICE | awk '{print $5 $6}')"
116         fi
117         ;;
118   *)
119         msg_usage "$0 {start|stop|restart|try-restart|force-reload|setup|status}"
120         exit 3
121 esac
122
123 exit $RETVAL
This page took 0.074858 seconds and 3 git commands to generate.