vboxdrv.sh.in revision 9b6c3413bf8a8eda0e1b71fda8ce7f7289470f0e
# Sun VirtualBox
# Linux kernel module init script
#
# Copyright (C) 2006-2009 Sun Microsystems, Inc.
#
# This file is part of VirtualBox Open Source Edition (OSE), as
# available from http://www.virtualbox.org. This file is free software;
# General Public License (GPL) as published by the Free Software
# Foundation, in version 2 as it comes in the "COPYING" file of the
# VirtualBox OSE distribution. VirtualBox OSE is distributed in the
# hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
#
# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
# Clara, CA 95054 USA or visit http://www.sun.com if you need
# additional information or have any questions.
#
# chkconfig: 35 30 70
# description: VirtualBox Linux kernel module
#
### BEGIN INIT INFO
# Provides: vboxdrv
# Required-Start: $syslog
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: VirtualBox Linux kernel module
### END INIT INFO
if [ -n "$INSTALL_DIR" ]; then
VBOXMANAGE="$INSTALL_DIR/VBoxManage"
else
VBOXMANAGE="/usr/lib/%PACKAGE%/VBoxManage"
BUILDVBOXDRV="/usr/share/%PACKAGE%/src/vboxdrv/build_in_tmp"
BUILDVBOXNETFLT="/usr/share/%PACKAGE%/src/vboxnetflt/build_in_tmp"
BUILDVBOXNETADP="/usr/share/%PACKAGE%/src/vboxnetadp/build_in_tmp"
fi
if [ -n "$NOLSB" ]; then
if [ -f /etc/redhat-release ]; then
elif [ -f /etc/SuSE-release ]; then
elif [ -f /etc/gentoo-release ]; then
fi
fi
if [ -z "$NOLSB" ]; then
echo ""
log_failure_msg "$1"
}
log_success_msg " done."
}
log_daemon_msg "$@"
}
else
if [ "$system" = "redhat" ]; then
echo -n " "
echo
echo " ($1)"
}
echo -n " "
echo
}
elif [ "$system" = "suse" ]; then
rc_status -v
echo " ($1)"
}
rc_status -v
}
elif [ "$system" = "gentoo" ]; then
if [ -f /sbin/functions.sh ]; then
. /sbin/functions.sh
fi
eerror "$1"
}
eend "$?"
}
ebegin "$1"
}
shift
fi
else
echo " ...failed!"
echo " ($1)"
}
echo " ...done."
}
fi
if [ "$system" != "gentoo" ]; then
[ -z "${1:-}" ] && return 1
if [ -z "${2:-}" ]; then
echo -n "$1"
else
echo -n "$1: $2"
fi
}
fi
fi
failure()
{
fail_msg "$1"
exit 0
}
running()
{
}
start()
{
begin_msg "Starting VirtualBox kernel module"
fi
# HACK: disable the hardware performance counter framework
if [ -e /proc/sys/kernel/perf_counter_paranoid ]; then
echo 2 > /proc/sys/kernel/perf_counter_paranoid
fi
failure "modprobe vboxdrv failed. Please use 'dmesg' to find out why"
fi
sleep .2
fi
# ensure the character special exists
if [ ! -c $DEVICE ]; then
MINOR=0
else
MAJOR=10
fi
fi
failure "Cannot locate the VirtualBox device"
fi
fi
fi
# ensure permissions
if ! chown :$GROUPNAME $DEVICE 2>/dev/null; then
rmmod vboxnetadp 2>/dev/null
rmmod vboxnetflt 2>/dev/null
failure "Cannot change owner $GROUPNAME for device $DEVICE"
fi
if ! modprobe vboxnetflt > /dev/null 2>&1; then
failure "modprobe vboxnetflt failed. Please use 'dmesg' to find out why"
fi
if ! modprobe vboxnetadp > /dev/null 2>&1; then
failure "modprobe vboxnetadp failed. Please use 'dmesg' to find out why"
fi
}
stop()
{
begin_msg "Stopping VirtualBox kernel module"
if running vboxnetadp; then
if ! rmmod vboxnetadp 2>/dev/null; then
failure "Cannot unload module vboxnetadp"
fi
fi
if running vboxnetflt; then
if ! rmmod vboxnetflt 2>/dev/null; then
failure "Cannot unload module vboxnetflt"
fi
fi
failure "Cannot unload module vboxdrv"
fi
fi
fi
}
# SHUTDOWN_USERS="foo bar"
# check for running VMs of user foo and user bar
# SHUTDOWN=poweroff
# SHUTDOWN=acpibutton
# SHUTDOWN=savestate
# select one of these shutdown methods for running VMs
stop_vms()
{
wait=0
for i in $SHUTDOWN_USERS; do
# don't create the ipcd directory with wrong permissions!
export VBOX_IPC_SOCKETID="$i"
begin_msg "Powering off remaining VMs"
done
begin_msg "Sending ACPI power button event to remaining VMs"
wait=30
done
begin_msg "Saving state of remaining VMs"
done
fi
fi
fi
done
# wait for some seconds when doing ACPI shutdown
fi
}
setup()
{
stop
begin_msg "Removing old VirtualBox netadp kernel module"
fi
begin_msg "Removing old VirtualBox netflt kernel module"
fi
begin_msg "Removing old VirtualBox kernel module"
fi
begin_msg "Recompiling VirtualBox kernel module"
if ! $BUILDVBOXDRV \
fi
if ! $BUILDVBOXNETFLT \
--use-module-symvers /tmp/vboxdrv-Module.symvers \
fi
if ! $BUILDVBOXNETADP \
--use-module-symvers /tmp/vboxdrv-Module.symvers \
fi
rm -f /etc/vbox/module_not_compiled
}
{
if running vboxnetflt; then
if running vboxnetadp; then
echo "VirtualBox kernel modules (vboxdrv, vboxnetflt and vboxnetadp) are loaded."
else
echo "VirtualBox kernel modules (vboxdrv and vboxnetflt) are loaded."
fi
else
echo "VirtualBox kernel module is loaded."
fi
for i in $SHUTDOWN_USERS; do
# don't create the ipcd directory with wrong permissions!
export VBOX_IPC_SOCKETID="$i"
echo "The following VMs are currently running:"
echo " $v"
done
fi
fi
done
else
echo "VirtualBox kernel module is not loaded."
fi
}
case "$1" in
;;
stop)
stop
;;
;;
stop && start
;;
stop
;;
;;
;;
*)
echo "Usage: $0 {start|stop|stop_vms|restart|force-reload|status|setup}"
exit 1
esac
exit 0