#!/bin/sh
# Startup script for lkst (kernel module) 
#
# chkconfig: 12345 04 96
# description: Install kernel module of Linux Kernel State Tracer

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

[ -x /usr/sbin/lkst ] || exit 0


start() {
    echo -n $"Starting Kernel State Tracer: " 
    if [ "x`/sbin/lsmod | grep lkst`" = x ] ;then # load
        if /sbin/insmod lkst &> /dev/null ;then
            echo_success; echo
	    return 1;
	else
	    echo_failure; echo
	    return 0;
        fi
    fi
    if [ ! `/usr/sbin/lkstm ls | grep "*" | cut -f 1 -d "*"` = "0" ]; then
        echo_passed; echo
        return 1;
    fi
    
    if /usr/sbin/lkst start &> /dev/null; then
        echo_success; echo
	return 1;
    else
        echo_failure; echo
	return 0;
    fi
}

stop() {
    echo -n $"Stopping Kernel State Tracer: "
    if  ( ( [ "x`/sbin/lsmod | grep lkst`" != x ] && /sbin/rmmod lkst &> /dev/null ) || /usr/sbin/lkst stop &>/dev/null ); then
        echo_success;
    else
        echo_failure;
    fi
    echo
}

case "$1" in
	start)
	    start
	    ;;
	
	stop)
	    stop
	    ;;
	
	status)
	    if /usr/sbin/lkst all &>/dev/null && [ x`/usr/sbin/lkstm ls | grep "0\*" ` = x ];then
	        echo "LKST is active."
	    else
	        echo "LKST is inactive."
	    fi
	    ;;
	restart)
	    stop
	    start
	    ;;
	
	*)
	    echo $"Usage: $0 {start|stop|restart|status}"
	    exit 1

esac

exit 0
