VirtualBox

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

Last change on this file since 4064 was 3862, checked in by vboxsync, 17 years ago

fixed a bunch of lintian warnings/errors, mostly by moving files to the right place

File size: 3.8 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# Short-Description: VirtualBox Linux kernel module
31### END INIT INFO
32
33KDIR="/lib/modules/`uname -r`/misc"
34DEVICE=/dev/vboxdrv
35MODNAME=vboxdrv
36GROUPNAME=vboxusers
37LOG="/var/log/vbox-install.log"
38NOLSB=%NOLSB%
39
40if [ -r /etc/default/virtualbox ]; then
41 . /etc/default/virtualbox
42fi
43
44if [ -z "$NOLSB" -a -f /lib/lsb/init-functions ]; then
45 . /lib/lsb/init-functions
46else
47 log_daemon_msg()
48 {
49 if [ -z "${1:-}" ]; then
50 return 1
51 fi
52 if [ -z "${2:-}" ]; then
53 echo -n "$1:"
54 return
55 fi
56 echo -n "$1: $2"
57 }
58 log_end_msg()
59 {
60 [ -z "${1:-}" ] && return 1
61 if [ $1 -eq 0 ]; then
62 echo "."
63 else
64 echo " failed!"
65 fi
66 }
67 log_success_msg()
68 {
69 echo "$@"
70 }
71 log_failure_msg()
72 {
73 echo "$@"
74 }
75fi
76
77failure()
78{
79 echo ""
80 log_failure_msg "$1"
81 exit 0
82}
83
84running()
85{
86 lsmod | grep -q $MODNAME[^_-]
87}
88
89start()
90{
91 log_daemon_msg "Starting VirtualBox kernel module" "$MODNAME";
92 # ensure the module is loaded
93 if ! running; then
94 if [ ! -f "$KDIR/$MODNAME.o" -a ! "$KDIR/$MODNAME.ko" ]; then
95 failure "No suitable module for running kernel found."
96 fi
97 if ! modprobe $MODNAME; then
98 failure "Modprobe $MODNAME failed. Please use 'dmesg' to find out why."
99 fi
100 sleep .2
101 fi
102 # ensure the character special exists
103 if [ ! -c $DEVICE ]; then
104 MAJOR=`sed -n 's;\([0-9]\+\) vboxdrv;\1;p' /proc/devices`
105 if [ -n "$MAJOR" ]; then
106 MINOR=0
107 else
108 MINOR=`sed -n 's;\([0-9]\+\) vboxdrv;\1;p' /proc/misc`
109 if [ -n "$MINOR" ]; then
110 MAJOR=10
111 fi
112 fi
113 if [ -z "$MAJOR" ]; then
114 rmmod $MODNAME
115 failure "Cannot locate device major."
116 fi
117 if ! mknod -m 0664 $DEVICE c $MAJOR $MINOR; then
118 rmmod $MODNAME
119 failure "Cannot create device $DEVICE with major $MAJOR and minor $MINOR."
120 fi
121 fi
122 # ensure permissions
123 if ! chown :$GROUPNAME $DEVICE; then
124 rmmod $MODNAME
125 failure "Cannot change owner $GROUPNAME for device $DEVICE."
126 fi
127 log_end_msg 0
128}
129
130stop()
131{
132 log_daemon_msg "Stopping VirtualBox kernel module" "$MODNAME";
133 killall -q VBoxSVC
134 if running; then
135 if ! rmmod $MODNAME; then
136 failure "Cannot unload module $MODNAME."
137 fi
138 if ! rm -f $DEVICE; then
139 failure "Cannot unlink $DEVICE."
140 fi
141 fi
142 log_end_msg 0
143}
144
145case "$1" in
146 start)
147 start
148 ;;
149 stop)
150 stop
151 ;;
152 restart|reload|force-reload)
153 stop
154 start
155 ;;
156 setup)
157 stop
158 log_daemon_msg "Recompiling VirtualBox kernel module" "$MODNAME"
159 if ! /usr/share/virtualbox/src/build_in_tmp install > $LOG 2>&1; then
160 failure "Look at $LOG to find out what went wrong"
161 fi
162 log_end_msg 0
163 start
164 ;;
165 status)
166 if running; then
167 log_success_msg "VirtualBox kernel module is loaded."
168 else
169 log_failure_msg "VirtualBox kernel module is not loaded."
170 fi
171 ;;
172 *)
173 log_failure_msg "Usage: $0 {start|stop|restart|status|setup}"
174 exit 3
175esac
176
177exit 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