#!/bin/sh
# init script for kqemu
#
# chkconfig: 2345 04 04
# description: The QEMU Accelerator Module increases the speed of QEMU when a PC is emulated on a PC.

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

prog="kqemu"

start() {
    echo -n $"Starting $prog: "
    echo 1024 > /proc/sys/dev/rtc/max-user-freq
    if [ -c /dev/kqemu ]; then
       /sbin/modprobe kqemu
    else
       rm -rf /dev/kqemu
       mknod /dev/kqemu c 250 0
       chmod 666 /dev/kqemu
       /sbin/depmod -a -q
       /sbin/modprobe kqemu
    fi
    RETVAL=$?
    if [ $RETVAL = "0" ]; then
       echo -n "$prog is started"
    else
       echo -n "$prog did not start."
    fi
    echo
    return $RETVAL
}

stop() {
    echo -n $"Stopping $prog: "
    /sbin/modprobe -r kqemu
    rm -rf /dev/kqemu
    RETVAL=$?
    if [ $RETVAL = "0" ]; then
       echo -n "$prog is stopped"
    fi
    echo
    return $RETVAL
}

case "$1" in
  	start)
	   start
	   ;;
  	stop)
	   stop
	   ;;
  	status)
           lsmod | grep kqemu > /dev/null
           if [ $? = "0" ]; then
              echo "$prog is loaded"
           else
              echo "$prog is not loaded"
           fi
	   ;;
 	 restart)
	   stop
	   start
	   ;;
  	*)
	echo "Usage: $0 {start|stop|restart|status}"
	exit 1
esac

exit $RETVAL
