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