VirtualBox

source: vbox/trunk/src/VBox/Installer/linux/vboxdrv.sh.in@ 8256

Last change on this file since 8256 was 8172, checked in by vboxsync, 17 years ago

rebranding

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 8.0 KB
Line 
1#! /bin/sh
2# Sun xVM VirtualBox
3# Linux kernel module init script
4
5#
6# Copyright (C) 2006-2007 Sun Microsystems, Inc.
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# chkconfig: 35 30 60
18# description: VirtualBox Linux kernel module
19#
20### BEGIN INIT INFO
21# Provides: vboxdrv
22# Required-Start: $syslog
23# Required-Stop:
24# Default-Start: 3 5
25# Default-Stop:
26# Short-Description: VirtualBox Linux kernel module
27### END INIT INFO
28
29PATH=/sbin:/bin:/usr/sbin:/usr/bin:$PATH
30DEVICE=/dev/vboxdrv
31MODNAME=vboxdrv
32GROUPNAME=vboxusers
33LOG="/var/log/vbox-install.log"
34NOLSB=%NOLSB%
35
36[ -f /lib/lsb/init-functions ] || NOLSB=yes
37[ -f /etc/vbox/vbox.cfg ] && . /etc/vbox/vbox.cfg
38
39if [ -n "$INSTALL_DIR" ]; then
40 VBOXMANAGE="$INSTALL_DIR/VBoxManage"
41 BUILDINTMP="$INSTALL_DIR/src/build_in_tmp"
42else
43 VBOXMANAGE="/usr/lib/virtualbox/VBoxManage"
44 BUILDINTMP="/usr/share/virtualbox/src/build_in_tmp"
45fi
46
47if [ -n "$NOLSB" ]; then
48 if [ -f /etc/redhat-release ]; then
49 system=redhat
50 elif [ -f /etc/SuSE-release ]; then
51 system=suse
52 elif [ -f /etc/gentoo-release ]; then
53 system=gentoo
54 fi
55fi
56
57[ -r /etc/default/virtualbox ] && . /etc/default/virtualbox
58
59if [ -z "$NOLSB" ]; then
60 . /lib/lsb/init-functions
61 fail_msg() {
62 echo ""
63 log_failure_msg "$1"
64 }
65 succ_msg() {
66 log_success_msg " done."
67 }
68 begin_msg() {
69 log_daemon_msg "$@"
70 }
71else
72 if [ "$system" = "redhat" ]; then
73 . /etc/init.d/functions
74 fail_msg() {
75 echo -n " "
76 echo_failure
77 echo
78 echo " ($1)"
79 }
80 succ_msg() {
81 echo -n " "
82 echo_success
83 echo
84 }
85 elif [ "$system" = "suse" ]; then
86 . /etc/rc.status
87 fail_msg() {
88 rc_failed 1
89 rc_status -v
90 echo " ($1)"
91 }
92 succ_msg() {
93 rc_reset
94 rc_status -v
95 }
96 elif [ "$system" = "gentoo" ]; then
97 . /sbin/functions.sh
98 fail_msg() {
99 eerror "$1"
100 }
101 succ_msg() {
102 eend "$?"
103 }
104 begin_msg() {
105 ebegin "$1"
106 }
107 if [ "`which $0`" = "/sbin/rc" ]; then
108 shift
109 fi
110 else
111 fail_msg() {
112 echo " ...failed!"
113 echo " ($1)"
114 }
115 succ_msg() {
116 echo " ...done."
117 }
118 fi
119 if [ "$system" != "gentoo" ]; then
120 begin_msg() {
121 [ -z "${1:-}" ] && return 1
122 if [ -z "${2:-}" ]; then
123 echo -n "$1"
124 else
125 echo -n "$1: $2"
126 fi
127 }
128 fi
129fi
130
131failure()
132{
133 fail_msg "$1"
134 exit 0
135}
136
137running()
138{
139 lsmod | grep -q "$MODNAME[^_-]"
140}
141
142start()
143{
144 begin_msg "Starting VirtualBox kernel module"
145 if ! running; then
146 if ! find /lib/modules/`uname -r` -name "vboxdrv\.*" 2>/dev/null|grep -q vboxdrv; then
147 failure "No suitable module for running kernel found"
148 fi
149 if ! rm -f $DEVICE; then
150 failure "Cannot remove $DEVICE"
151 fi
152 if ! modprobe $MODNAME > /dev/null 2>&1; then
153 failure "modprobe $MODNAME failed. Please use 'dmesg' to find out why"
154 fi
155 sleep .2
156 fi
157 # ensure the character special exists
158 if [ ! -c $DEVICE ]; then
159 MAJOR=`sed -n 's;\([0-9]\+\) vboxdrv;\1;p' /proc/devices`
160 if [ ! -z "$MAJOR" ]; then
161 MINOR=0
162 else
163 MINOR=`sed -n 's;\([0-9]\+\) vboxdrv;\1;p' /proc/misc`
164 if [ ! -z "$MINOR" ]; then
165 MAJOR=10
166 fi
167 fi
168 if [ -z "$MAJOR" ]; then
169 rmmod $MODNAME 2>/dev/null
170 failure "Cannot locate the VirtualBox device"
171 fi
172 if ! mknod -m 0660 $DEVICE c $MAJOR $MINOR 2>/dev/null; then
173 rmmod $MODNAME 2>/dev/null
174 failure "Cannot create device $DEVICE with major $MAJOR and minor $MINOR"
175 fi
176 fi
177 # ensure permissions
178 if ! chown :$GROUPNAME $DEVICE 2>/dev/null; then
179 rmmod $MODNAME 2>/dev/null
180 failure "Cannot change owner $GROUPNAME for device $DEVICE"
181 fi
182 succ_msg
183}
184
185stop()
186{
187 begin_msg "Stopping VirtualBox kernel module"
188 if running; then
189 if ! rmmod $MODNAME 2>/dev/null; then
190 failure "Cannot unload module $MODNAME"
191 fi
192 if ! rm -f $DEVICE; then
193 failure "Cannot unlink $DEVICE"
194 fi
195 fi
196 succ_msg
197}
198
199# enter the following variables in /etc/default/virtualbox:
200# SHUTDOWN_USERS="foo bar"
201# check for running VMs of user foo and user bar
202# SHUTDOWN=poweroff
203# SHUTDOWN=acpibutton
204# SHUTDOWN=savestate
205# select one of these shutdown methods for running VMs
206stop_vms()
207{
208 wait=0
209 for i in $SHUTDOWN_USERS; do
210 # don't create the ipcd directory with wrong permissions!
211 if [ -d /tmp/.vbox-$i-ipc ]; then
212 export VBOX_IPC_SOCKETID="$i"
213 VMS=`$VBOXMANAGE -nologo list runningvms 2>/dev/null`
214 if [ -n "$VMS" ]; then
215 if [ "$SHUTDOWN" = "poweroff" ]; then
216 begin_msg "Powering off remaining VMs"
217 for v in $VMS; do
218 $VBOXMANAGE -nologo controlvm $v poweroff
219 done
220 succ_msg
221 elif [ "$SHUTDOWN" = "acpibutton" ]; then
222 begin_msg "Sending ACPI power button event to remaining VMs"
223 for v in $VMS; do
224 $VBOXMANAGE -nologo controlvm $v acpipowerbutton
225 wait=30
226 done
227 succ_msg
228 elif [ "$SHUTDOWN" = "savestate" ]; then
229 begin_msg "Saving state of remaining VMs"
230 for v in $VMS; do
231 $VBOXMANAGE -nologo controlvm $v savestate
232 done
233 succ_msg
234 fi
235 fi
236 fi
237 done
238 # wait for some seconds when doing ACPI shutdown
239 if [ "$wait" -ne 0 ]; then
240 begin_msg "Waiting for $wait seconds for VM shutdown"
241 sleep $wait
242 succ_msg
243 fi
244}
245
246setup()
247{
248 stop
249 if find /lib/modules/`uname -r` -name "vboxdrv\.*" 2>/dev/null|grep -q vboxdrv; then
250 begin_msg "Removing old VirtualBox kernel module"
251 find /lib/modules/`uname -r` -name "vboxdrv\.*" 2>/dev/null|xargs rm -f 2>/dev/null
252 succ_msg
253 fi
254 begin_msg "Recompiling VirtualBox kernel module"
255 if ! $BUILDINTMP install > $LOG 2>&1; then
256 failure "Look at $LOG to find out what went wrong"
257 fi
258 succ_msg
259 start
260}
261
262dmnstatus()
263{
264 if running; then
265 echo "VirtualBox kernel module is loaded."
266 for i in $SHUTDOWN_USERS; do
267 # don't create the ipcd directory with wrong permissions!
268 if [ -d /tmp/.vbox-$i-ipc ]; then
269 export VBOX_IPC_SOCKETID="$i"
270 VMS=`$VBOXMANAGE -nologo list runningvms 2>/dev/null`
271 if [ -n "$VMS" ]; then
272 echo "The following VMs are currently running:"
273 for v in $VMS; do
274 echo " $v"
275 done
276 fi
277 fi
278 done
279 else
280 echo "VirtualBox kernel module is not loaded."
281 fi
282}
283
284case "$1" in
285start)
286 start
287 ;;
288stop)
289 stop_vms
290 stop
291 ;;
292stop_vms)
293 stop_vms
294 ;;
295restart)
296 stop && start
297 ;;
298force-reload)
299 stop
300 start
301 ;;
302setup)
303 setup
304 ;;
305status)
306 dmnstatus
307 ;;
308*)
309 echo "Usage: $0 {start|stop|stop_vms|restart|force-reload|status|setup}"
310 exit 1
311esac
312
313exit 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