#!/bin/sh
#
# virtualbox	VirtualBox virtualizer for x86 hardware
#
# chkconfig:	345 84 25
#
# description:	Oracle VirtualBox is a general-purpose full virtualizer for x86 \
#		hardware. Targeted at server, desktop and embedded use.
#
# $Id$

# Source function library
. /etc/rc.d/init.d/functions

VBOX_MODULE="vboxnetflt"

# Get service config - may override defaults
[ -f /etc/sysconfig/virtualbox ] && . /etc/sysconfig/virtualbox

start() {
	if [ -f /var/lock/subsys/vboxnetflt ]; then
		return
	fi

	modprobe -s $VBOX_MODULE
	touch /var/lock/subsys/vboxnetflt
}

stop() {
	# NOTE: rmmod will wait if device is in use, so automatic rmmod probably is not the best idea
	/sbin/rmmod $VBOX_MODULE
	rm -f /var/lock/subsys/vboxnetflt
}

condrestart() {
	if [ ! -f /var/lock/subsys/vboxnetflt ]; then
		RETVAL=$1
		return
	fi

	stop
	start
}

RETVAL=0
# See how we were called.
case "$1" in
  start)
  	start
	;;
  stop)
  	stop
	;;
  restart)
	stop
	start
	;;
  try-restart)
	condrestart 0
	;;
  force-reload)
	condrestart 7
	;;
  status)
	if ! is_module $VBOX_MODULE; then
		echo "$VBOX_MODULE module is loaded"
	else
		echo "$VBOX_MODULE module is not loaded"
		RETVAL=3
	fi
	;;
  *)
	msg_usage "$0 {start|stop|restart|try-restart|force-reload|status}"
	exit 3
esac

exit $RETVAL
