~ubuntu-branches/ubuntu/vivid/virtualbox-ose/vivid

« back to all changes in this revision

Viewing changes to debian/virtualbox-ose.init

  • Committer: Bazaar Package Importer
  • Author(s): Felix Geyer
  • Date: 2009-10-13 23:06:00 UTC
  • mfrom: (0.3.2 upstream) (0.1.12 sid)
  • Revision ID: james.westby@ubuntu.com-20091013230600-xhu2pwizq0wo63l9
Tags: 3.0.8-dfsg-1ubuntu1
* Merge from debian unstable (LP: #444812), remaining changes:
  - Enable DKMS support on virtualbox host and guest modules (LP: #267097)
    - Drop virtualbox-ose{-guest,}-modules-* package templates
    - Recommend *-source instead of *-modules packages
    - Replace error messages related to missing/mismatched
      kernel module accordingly
  - Autoload kernel module
    - LOAD_VBOXDRV_MODULE=1 in virtualbox-ose.default
  - Disable update action
    - patches/u01-disable-update-action.dpatch
  - Virtualbox should go in Accessories, not in System tools (LP: #288590)
    - virtualbox-ose-qt.files/virtualbox-ose.desktop
  - Add apport hook
    - virtualbox-ose.files/source_virtualbox-ose.py
    - virtualbox-ose.install
  - Add launchpad integration
    - control
    - lpi-bug.xpm
    - patches/u02-lp-integration.dpatch
* Try to remove existing dkms modules before adding the new modules
  (LP: #434503)
  - debian/virtualbox-ose-source.postinst
  - debian/virtualbox-ose-guest-source.postinst
* Don't fail if dkms modules have already been removed
  - debian/virtualbox-ose-source.prerm
  - debian/virtualbox-ose-guest-source.prerm

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /bin/sh
 
2
# Sun VirtualBox
 
3
# Linux kernel module init script
 
4
 
 
5
#
 
6
# Copyright (C) 2006-2009 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 70
 
18
# description: VirtualBox Linux kernel module
 
19
#
 
20
### BEGIN INIT INFO
 
21
# Provides:       vboxdrv virtualbox-ose
 
22
# Required-Start: $remote_fs $network
 
23
# Required-Stop:  $remote_fs
 
24
# Default-Start:  2 3 4 5
 
25
# Default-Stop:   0 1 6
 
26
# Short-Description: VirtualBox Linux kernel module
 
27
### END INIT INFO
 
28
 
 
29
. /lib/lsb/init-functions
 
30
 
 
31
test -d /usr/share/doc/virtualbox-ose -a -x /usr/bin/VBoxHeadless || exit 0
 
32
 
 
33
# Include virtualbox-ose defaults if available
 
34
[ -r /etc/default/virtualbox-ose ] && . /etc/default/virtualbox-ose
 
35
 
 
36
# set list of all active users if asked to do so
 
37
if [ "$SHUTDOWN_USERS" = "all" ]; then
 
38
        SHUTDOWN_USERS=""
 
39
        for i in /tmp/.vbox-*-ipc; do
 
40
                SHUTDOWN_USERS="$SHUTDOWN_USERS $(echo $i|cut -d'-' -f2)"
 
41
        done
 
42
fi
 
43
 
 
44
if [ "$LOAD_VBOXDRV_MODULE" != 1 ]; then
 
45
        log_success_msg "virtualbox-ose disabled; edit /etc/default/virtualbox-ose"
 
46
        exit 0
 
47
fi
 
48
 
 
49
running()
 
50
{
 
51
    lsmod | grep -q "$1[^_-]"
 
52
}
 
53
 
 
54
start()
 
55
{
 
56
        log_begin_msg "Starting VirtualBox kernel modules"
 
57
        
 
58
        if ! running vboxdrv; then
 
59
                # HACK: disable the hardware performance counter framework
 
60
                if [ -e /proc/sys/kernel/perf_counter_paranoid ]; then
 
61
                        if [ $(cat /proc/sys/kernel/perf_counter_paranoid) -ne 2 ]; then
 
62
                                log_warning_msg "Disabling the hardware performance counter framework"
 
63
                                echo 2 > /proc/sys/kernel/perf_counter_paranoid 
 
64
                        fi
 
65
                fi
 
66
                
 
67
                if ! modprobe vboxdrv > /dev/null 2>&1; then
 
68
                        if ! find /lib/modules/`uname -r` -name "vboxdrv\.*" 2>/dev/null|grep -q vboxdrv; then
 
69
                                log_failure_msg "No suitable module for running kernel found"
 
70
                        else
 
71
                                log_failure_msg "modprobe vboxdrv failed. Please use 'dmesg' to find out why"
 
72
                        fi
 
73
                        log_end_msg 1
 
74
                        return 1
 
75
                fi
 
76
        fi
 
77
        
 
78
        if ! running vboxnetadp; then
 
79
                if ! modprobe vboxnetadp > /dev/null 2>&1; then
 
80
                        if ! find /lib/modules/`uname -r` -name "vboxnetadp\.*" 2>/dev/null|grep -q vboxnetadp; then
 
81
                                log_failure_msg "No suitable vboxnetflt module for running kernel found"
 
82
                        else
 
83
                                log_failure_msg "modprobe vboxnetflt failed. Please use 'dmesg' to find out why"
 
84
                        fi
 
85
                        log_end_msg 1
 
86
                        return 1
 
87
                fi
 
88
        fi
 
89
        
 
90
        if ! running vboxnetflt; then
 
91
                if ! modprobe vboxnetflt > /dev/null 2>&1; then
 
92
                        if ! find /lib/modules/`uname -r` -name "vboxnetflt\.*" 2>/dev/null|grep -q vboxnetflt; then
 
93
                                log_failure_msg "No suitable vboxnetadp module for running kernel found"
 
94
                        else
 
95
                                log_failure_msg "modprobe vboxnetadp failed. Please use 'dmesg' to find out why"
 
96
                        fi
 
97
                        log_end_msg 1
 
98
                        return 1
 
99
                fi
 
100
        fi
 
101
        
 
102
        log_end_msg 0
 
103
}
 
104
 
 
105
stop()
 
106
{
 
107
        log_begin_msg "Stopping VirtualBox kernel modules"
 
108
        
 
109
        if running vboxnetadp; then
 
110
                if ! rmmod vboxnetadp 2>/dev/null; then
 
111
                        log_failure_msg "Cannot unload module vboxnetadp"
 
112
                        log_end_msg 1
 
113
                        return 1
 
114
                fi
 
115
        fi
 
116
        
 
117
        if running vboxdrv; then
 
118
                if running vboxnetflt; then
 
119
                        if ! rmmod vboxnetflt 2>/dev/null; then
 
120
                                log_failure_msg "Cannot unload module vboxnetflt"
 
121
                                log_end_msg 1
 
122
                                return 1
 
123
                        fi
 
124
                fi
 
125
                
 
126
                if ! rmmod vboxdrv 2>/dev/null; then
 
127
                        log_failure_msg "Cannot unload module vboxdrv"
 
128
                        log_end_msg 1
 
129
                        return 1
 
130
                fi
 
131
        fi
 
132
        
 
133
        log_end_msg 0
 
134
}
 
135
 
 
136
# enter the following variables in /etc/default/virtualbox-ose:
 
137
#   SHUTDOWN_USERS="foo bar"  
 
138
#     check for running VMs of user foo and user bar
 
139
#   SHUTDOWN=poweroff
 
140
#   SHUTDOWN=acpibutton
 
141
#   SHUTDOWN=savestate
 
142
#     select one of these shutdown methods for running VMs
 
143
stop_vms()
 
144
{
 
145
        if ! pidof VBoxSVC > /dev/null; then
 
146
                return 0
 
147
        fi
 
148
        
 
149
        wait=0
 
150
        
 
151
        for i in $SHUTDOWN_USERS; do
 
152
                if [ -d /tmp/.vbox-$i-ipc ]; then
 
153
                        export VBOX_IPC_SOCKETID="$i"
 
154
                        VMS=`VBoxManage --nologo list runningvms 2>/dev/null`
 
155
                        if [ $? -eq 0 -a -n "$VMS" ]; then
 
156
                                VMS=`echo "$VMS" | sed -e 's/^".*".*{\(.*\)}/\1/'`
 
157
                                if [ "$SHUTDOWN" = "poweroff" ]; then
 
158
                                        log_action_msg "Powering off remaining VMs from user $i"
 
159
                                        for v in $VMS; do
 
160
                                                VBoxManage --nologo controlvm $v poweroff
 
161
                                                wait=10
 
162
                                        done
 
163
                                elif [ "$SHUTDOWN" = "acpibutton" ]; then
 
164
                                        log_action_msg "Sending ACPI power button event to remaining VMs from user $i"
 
165
                                        for v in $VMS; do
 
166
                                                VBoxManage --nologo controlvm $v acpipowerbutton
 
167
                                                wait=30
 
168
                                        done
 
169
                                elif [ "$SHUTDOWN" = "savestate" ]; then
 
170
                                        log_action_msg "Saving state of remaining VMs from user $i"
 
171
                                        for v in $VMS; do
 
172
                                                VBoxManage --nologo controlvm $v savestate
 
173
                                                wait=30
 
174
                                        done
 
175
                                fi
 
176
                        fi
 
177
                fi
 
178
        done
 
179
        
 
180
        # wait for some seconds when doing ACPI shutdown
 
181
        if [ "$wait" -ne 0 ]; then
 
182
                log_action_begin_msg "Waiting for $wait seconds for VM shutdown"
 
183
                sleep $wait
 
184
                log_action_end_msg 0
 
185
        fi
 
186
        return 0
 
187
}
 
188
 
 
189
dmnstatus()
 
190
{
 
191
        if running vboxdrv; then
 
192
                if running vboxnetflt; then
 
193
                        if running vboxnetadp; then
 
194
                                echo "VirtualBox kernel modules (vboxdrv, vboxnetflt and vboxnetadp) are loaded."
 
195
                        else
 
196
                                echo "VirtualBox kernel modules (vboxdrv and vboxnetflt) are loaded."
 
197
                        fi
 
198
                else
 
199
                  echo "VirtualBox kernel module is loaded."
 
200
                fi
 
201
                
 
202
                for i in $SHUTDOWN_USERS; do
 
203
                        if [ -d /tmp/.vbox-$i-ipc ]; then
 
204
                                export VBOX_IPC_SOCKETID="$i"
 
205
                                VMS=`VBoxManage --nologo list runningvms 2>/dev/null`
 
206
                                if [ $? -eq 0 -a -n "$VMS" ]; then
 
207
                                        VMS=`echo "$VMS" | sed -e 's/^".*".*{\(.*\)}/\1/'`
 
208
                                        echo "The following VMs are currently running:"
 
209
                                        for v in $VMS; do
 
210
                                                echo "  $v"
 
211
                                        done
 
212
                                fi
 
213
                        fi
 
214
                done
 
215
                return 0
 
216
        else
 
217
                echo "VirtualBox kernel module is not loaded."
 
218
                return 3
 
219
        fi
 
220
}
 
221
 
 
222
case "$1" in
 
223
start)
 
224
        start
 
225
        ;;
 
226
stop)
 
227
        stop_vms && stop
 
228
        ;;
 
229
stop_vms)
 
230
        stop_vms
 
231
        ;;
 
232
restart|force-reload)
 
233
        stop_vms && stop && start
 
234
        ;;
 
235
status)
 
236
        dmnstatus
 
237
        ;;
 
238
*)
 
239
        echo "Usage: $0 {start|stop|stop_vms|restart|force-reload|status}"
 
240
        exit 1
 
241
esac