VirtualBox

source: vbox/trunk/debian/vboxdrv.init.tmpl@ 3852

Last change on this file since 3852 was 3848, checked in by vboxsync, 17 years ago

reexport

File size: 3.9 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 as published by the Free Software Foundation,
12# in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
13# distribution. VirtualBox OSE is distributed in the hope that it will
14# be useful, but WITHOUT ANY WARRANTY of any kind.
15#
16# If you received this file as part of a commercial VirtualBox
17# distribution, then only the terms of your commercial VirtualBox
18# license agreement apply instead of the previous paragraph.
19
20
21# chkconfig: 35 30 60
22# description: VirtualBox Linux kernel module
23#
24### BEGIN INIT INFO
25# Provides: vboxdrv
26# Required-Start: $syslog
27# Required-Stop:
28# Default-Start: 3 5
29# Default-Stop:
30# Description: VirtualBox Linux kernel module
31### END INIT INFO
32
33KDIR="/lib/modules/`uname -r`/misc"
34DEVICE=/dev/vboxdrv
35MODNAME=vboxdrv
36GROUPNAME=vboxusers
37CONFIG="/etc/vbox/vbox.cfg"
38LOG="/var/log/vbox-install.log"
39NOLSB=%NOLSB%
40
41if [ -r /etc/default/virtualbox ]; then
42 . /etc/default/virtualbox
43fi
44
45if [ -z "$NOLSB" -a -f /lib/lsb/init-functions ]; then
46 . /lib/lsb/init-functions
47else
48 log_daemon_msg()
49 {
50 if [ -z "${1:-}" ]; then
51 return 1
52 fi
53 if [ -z "${2:-}" ]; then
54 echo -n "$1:"
55 return
56 fi
57 echo -n "$1: $2"
58 }
59 log_end_msg()
60 {
61 [ -z "${1:-}" ] && return 1
62 if [ $1 -eq 0 ]; then
63 echo "."
64 else
65 echo " failed!"
66 fi
67 }
68 log_success_msg()
69 {
70 echo "$@"
71 }
72 log_failure_msg()
73 {
74 echo "$@"
75 }
76fi
77
78failure()
79{
80 echo ""
81 log_failure_msg "$1"
82 exit 0
83}
84
85running()
86{
87 lsmod | grep -q $MODNAME[^_-]
88}
89
90start()
91{
92 log_daemon_msg "Starting VirtualBox kernel module" "$MODNAME";
93 # ensure the module is loaded
94 if ! running; then
95 if [ ! -f "$KDIR/$MODNAME.o" -a ! "$KDIR/$MODNAME.ko" ]; then
96 failure "No suitable module for running kernel found."
97 fi
98 if ! modprobe $MODNAME; then
99 failure "Modprobe $MODNAME failed. Please use 'dmesg' to find out why."
100 fi
101 sleep .2
102 fi
103 # ensure the character special exists
104 if [ ! -c $DEVICE ]; then
105 MAJOR=`sed -n 's;\([0-9]\+\) vboxdrv;\1;p' /proc/devices`
106 if [ -n "$MAJOR" ]; then
107 MINOR=0
108 else
109 MINOR=`sed -n 's;\([0-9]\+\) vboxdrv;\1;p' /proc/misc`
110 if [ -n "$MINOR" ]; then
111 MAJOR=10
112 fi
113 fi
114 if [ -z "$MAJOR" ]; then
115 rmmod $MODNAME
116 failure "Cannot locate device major."
117 fi
118 if ! mknod -m 0664 $DEVICE c $MAJOR $MINOR; then
119 rmmod $MODNAME
120 failure "Cannot create device $DEVICE with major $MAJOR and minor $MINOR."
121 fi
122 fi
123 # ensure permissions
124 if ! chown :$GROUPNAME $DEVICE; then
125 rmmod $MODNAME
126 failure "Cannot change owner $GROUPNAME for device $DEVICE."
127 fi
128 log_end_msg 0
129}
130
131stop()
132{
133 log_daemon_msg "Stopping VirtualBox kernel module" "$MODNAME";
134 killall -q VBoxSVC
135 if running; then
136 if ! rmmod $MODNAME; then
137 failure "Cannot unload module $MODNAME."
138 fi
139 if ! rm -f $DEVICE; then
140 failure "Cannot unlink $DEVICE."
141 fi
142 fi
143 log_end_msg 0
144}
145
146case "$1" in
147 start)
148 start
149 ;;
150 stop)
151 stop
152 ;;
153 restart|reload|force-reload)
154 stop
155 start
156 ;;
157 setup)
158 . "$CONFIG"
159 stop
160 log_daemon_msg "Recompiling VirtualBox kernel module" "$MODNAME"
161 if ! $INSTALL_DIR/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