#!/bin/sh
#
# kqemu		Load/unload the QEMU accelerator (kqemu) kernel module.
#
# chkconfig: 345 90 10
# description:	The kqemu service handles loading and unloading of the \
#		QEMU accelerator (kqemu) kernel module.

# Do not load RH compatibility interface.
WITHOUT_RC_COMPAT=1

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

LOCKFILE=/var/lock/subsys/kqemu
RETVAL=0

start()
{
	action "Loading QEMU accelerator module (kqemu):" modprobe kqemu
	RETVAL=$?
	[ $RETVAL = 0 ] && touch "$LOCKFILE" ||:
	return $RETVAL
}

stop()
{
	action "Unloading QEMU accelerator module (kqemu):" modprobe -r kqemu
	RETVAL=$?
	[ $RETVAL = 0 ] && rm -f "$LOCKFILE" ||:
	return $RETVAL
}

restart()
{
	stop
	start
}

status()
{
	if /sbin/lsmod | grep -qs '^kqemu[[:space:]]'; then
		echo "kqemu module is loaded"
		return 0
	elif [ -f "$LOCKFILE" ]; then
		echo "kqemu module is not loaded, but subsystem is locked"
		return 2
	else
		echo "kqemu service is stopped"
		return 3
	fi
}

# See how we were called.
case "$1" in
	start)
		start
		;;
	stop)
		stop
		;;
	restart)
		restart
		;;
	condstop)
		if [ -e "$LOCKFILE" ]; then
			stop
		fi
		;;
	condrestart)
		# Do nothing on package upgrade
		;;
	status)
		status
		RETVAL=$?
		;;
	*)
		msg_usage "${0##*/} {start|stop|restart|condstop|condrestart|status}"
		RETVAL=1
esac

exit $RETVAL
