]> git.pld-linux.org Git - packages/VirtualBox.git/blob - VirtualBox-vboxnetadp.init
- also create the device
[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:  InnoTek 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         if [ -d /dev/.udev ]; then
25                 return $RETVAL
26         fi
27
28         # set proper $VBOX_DEVICE for systems with static dev
29         show "Setting $VBOX_DEVICE entry"; busy
30         rm -f $VBOX_DEVICE
31         VBOX_MAJOR=$(awk -vdevice="${VBOX_DEVICE#/dev/}" '$2 == device {print $1}' /proc/devices)
32         if [ -n "$VBOX_MAJOR" ]; then
33                 VBOX_MINOR=0
34         else
35                 VBOX_MINOR=$(awk -vdevice="${VBOX_DEVICE#/dev/}" '$2 == device {print $1}' /proc/misc)
36                 if [ -n "$VBOX_MINOR" ]; then
37                         VBOX_MAJOR=$(awk '$2 == "misc" {print $1}' /proc/devices)
38                 fi
39         fi
40
41         if [ -z "$VBOX_MAJOR" ]; then
42                 /sbin/rmmod $VBOX_MODULE
43                 RETVAL=1
44         elif ! mknod -m 0660 $VBOX_DEVICE c $VBOX_MAJOR $VBOX_MINOR; then
45                 RETVAL=$?
46                 rmmod $VBOX_MODNAME
47                 fail
48         elif ! chown root:vbox $VBOX_DEVICE; then
49                 RETVAL=$?
50                 fail
51         else
52                 ok
53         fi
54         return $RETVAL
55 }
56
57 start() {
58         if [ -f /var/lock/subsys/$VBOX_MODULE ]; then
59                 return
60         fi
61
62         setup || exit $?
63         touch /var/lock/subsys/$VBOX_MODULE
64 }
65
66 stop() {
67         # NOTE: rmmod will wait if device is in use, so automatic rmmod probably is not the best idea
68         /sbin/rmmod $VBOX_MODULE
69         rm -f /var/lock/subsys/$VBOX_MODULE
70 }
71
72 condrestart() {
73         if [ -f /var/lock/subsys/$VBOX_MODULE ]; then
74                 stop
75                 start
76         else
77                 RETVAL=$1
78         fi
79 }
80
81 RETVAL=0
82 # See how we were called.
83 case "$1" in
84   start)
85         start
86         ;;
87   stop)
88         stop
89         ;;
90   restart)
91         stop
92         start
93         ;;
94   try-restart)
95         condrestart 0
96         ;;
97   force-reload)
98         condrestart 7
99         ;;
100   setup)
101         setup
102         ;;
103   status)
104         if ! is_module $VBOX_MODULE; then
105                 echo "$VBOX_MODULE module is loaded"
106         else
107                 echo "$VBOX_MODULE module is not loaded"
108                 RETVAL=3
109         fi
110         if [ ! -c $VBOX_DEVICE ]; then
111                 echo "$VBOX_DEVICE does not exist"
112                 RETVAL=3
113         else
114                 echo "$VBOX_DEVICE exists with major/minor $(ls -l $VBOX_DEVICE | awk '{print $5 $6}')"
115         fi
116         ;;
117   *)
118         msg_usage "$0 {start|stop|restart|try-restart|force-reload|setup|status}"
119         exit 3
120 esac
121
122 exit $RETVAL
This page took 0.087747 seconds and 4 git commands to generate.