VirtualBox

source: vbox/trunk/debian/vboxdrv.init.in@ 6356

Last change on this file since 6356 was 6332, checked in by vboxsync, 17 years ago

sync deb

File size: 4.0 KB
Line 
1#! /bin/bash
2#
3# innotek VirtualBox
4# Linux kernel module init script
5#
6# Copyright (C) 2006-2007 innotek GmbH
7#
8# This file is part of VirtualBox Open Source Edition (OSE), as
9# available from http://www.virtualbox.org. This file is free software;
10# you can redistribute it and/or modify it under the terms of the GNU
11# General Public License (GPL) as published by the Free Software
12# Foundation, in version 2 as it comes in the "COPYING" file of the
13# VirtualBox OSE distribution. VirtualBox OSE is distributed in the
14# hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
15#
16
17
18# chkconfig: 35 30 60
19# description: VirtualBox Linux kernel module
20#
21### BEGIN INIT INFO
22# Provides: vboxdrv
23# Required-Start: $syslog
24# Required-Stop:
25# Default-Start: 3 5
26# Default-Stop:
27# Short-Description: VirtualBox Linux kernel module
28### END INIT INFO
29
30KDIR="/lib/modules/`uname -r`/misc"
31DEVICE=/dev/vboxdrv
32MODNAME=vboxdrv
33GROUPNAME=vboxusers
34LOG="/var/log/vbox-install.log"
35NOLSB=%NOLSB%
36
37if [ -r /etc/default/virtualbox-ose ]; then
38 . /etc/default/virtualbox-ose
39fi
40
41if [ -z "$NOLSB" -a -f /lib/lsb/init-functions ]; then
42 . /lib/lsb/init-functions
43else
44 log_daemon_msg()
45 {
46 if [ -z "${1:-}" ]; then
47 return 1
48 fi
49 if [ -z "${2:-}" ]; then
50 echo -n "$1:"
51 return
52 fi
53 echo -n "$1: $2"
54 }
55 log_end_msg()
56 {
57 [ -z "${1:-}" ] && return 1
58 if [ $1 -eq 0 ]; then
59 echo "."
60 else
61 echo " failed!"
62 fi
63 }
64 log_success_msg()
65 {
66 echo "$@"
67 }
68 log_failure_msg()
69 {
70 echo "$@"
71 }
72fi
73
74failure()
75{
76 echo ""
77 log_failure_msg "$1"
78 exit 0
79}
80
81running()
82{
83 lsmod | grep -q "$MODNAME[^_-]"
84}
85
86start()
87{
88 log_daemon_msg "Starting VirtualBox kernel module" "$MODNAME";
89 # ensure the module is loaded
90 if ! running; then
91 if [ ! -f "$KDIR/$MODNAME.o" -a ! "$KDIR/$MODNAME.ko" ]; then
92 failure "No suitable module for running kernel found."
93 fi
94 if ! modprobe $MODNAME > /dev/null 2>&1; then
95 failure "Modprobe $MODNAME failed. Please use 'dmesg' to find out why."
96 fi
97 sleep .2
98 fi
99 # ensure the character special exists
100 if [ ! -c $DEVICE ]; then
101 MAJOR=`sed -n 's;\([0-9]\+\) vboxdrv;\1;p' /proc/devices`
102 if [ -n "$MAJOR" ]; then
103 MINOR=0
104 else
105 MINOR=`sed -n 's;\([0-9]\+\) vboxdrv;\1;p' /proc/misc`
106 if [ -n "$MINOR" ]; then
107 MAJOR=10
108 fi
109 fi
110 if [ -z "$MAJOR" ]; then
111 rmmod $MODNAME
112 failure "Cannot locate device major."
113 fi
114 if ! mknod -m 0660 $DEVICE c $MAJOR $MINOR; then
115 rmmod $MODNAME
116 failure "Cannot create device $DEVICE with major $MAJOR and minor $MINOR."
117 fi
118 fi
119 # ensure permissions
120 if ! chown :$GROUPNAME $DEVICE; then
121 rmmod $MODNAME
122 failure "Cannot change owner $GROUPNAME for device $DEVICE."
123 fi
124 log_end_msg 0
125}
126
127stop()
128{
129 log_daemon_msg "Stopping VirtualBox kernel module" "$MODNAME";
130 killall -q VBoxSVC
131 if running; then
132 if ! rmmod $MODNAME 2>/dev/null; then
133 failure "Cannot unload module $MODNAME."
134 fi
135 if ! rm -f $DEVICE; then
136 failure "Cannot unlink $DEVICE."
137 fi
138 fi
139 log_end_msg 0
140}
141
142case "$1" in
143 start)
144 start
145 ;;
146 stop)
147 stop
148 ;;
149 restart|reload|force-reload)
150 stop
151 start
152 ;;
153 setup)
154 stop
155 if find /lib/modules/`uname -r` -name "vboxdrv\.*" 2>/dev/null|grep -q vboxdrv; then
156 log_action_begin_msg "Removing old VirtualBox kernel module"
157 find /lib/modules/`uname -r` -name "vboxdrv\.*" 2>/dev/null|xargs rm -f 2>/dev/null
158 log_action_end_msg 0
159 fi
160 log_daemon_msg "Recompiling VirtualBox kernel module" "$MODNAME"
161 if ! /usr/share/virtualbox-ose/src/build_in_tmp install > $LOG 2>&1; then
162 failure "Look at $LOG to find out what went wrong"
163 fi
164 log_end_msg 0
165 start
166 ;;
167 status)
168 if running; then
169 log_success_msg "VirtualBox kernel module is loaded."
170 else
171 log_failure_msg "VirtualBox kernel module is not loaded."
172 fi
173 ;;
174 *)
175 log_failure_msg "Usage: $0 {start|stop|restart|status|setup}"
176 exit 3
177esac
178
179exit 0
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette