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