#!/bin/sh
#
# chkconfig: - 86 14
# description: whatap infra monitoring
# processname: whatap_infrad
# config: /usr/whatap/infra/conf/whatap.conf
#

### BEGIN INIT INFO
# Provides: whatap-infra
# Required-Start: $local_fs $network
# Required-Stop: $local_fs $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start and stop whatap infra agent
# Description: whatap infra monitoring agent
### END INIT INFO

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

export MALLOC_ARENA_MAX=2
export WHATAP_HOME=/usr/whatap/infra/conf
export GOTRACEBACK=all

if [ -x /usr/whatap/infra/whatap_infrad ]; then
    exec=/usr/whatap/infra/whatap_infrad
else
    exit 5
fi

prog=${exec##*/}

lockfile=/var/lock/subsys/whatap-infra

start()
{
    logger -t "whatap init" "try start"
    echo -n $"Starting Whatap Infra: "
    daemon $exec 
    rv=$?
    echo
    [ $rv -eq 0 ] && touch $lockfile
    logger -t "whatap init" "start end"
    return $rv
}

stop()
{
    logger -t "whatap init" "try stop"
    echo -n $"Shutting down Whatap Infra: "
    killproc $prog
    rv=$?
    echo
    [ $rv -eq 0 ] && rm -f $lockfile
    logger -t "whatap init" "stop end"
    return $rv
}

restart()
{
    logger -t "whatap init" "try restart"
    stop
    start
    logger -t "whatap init" "restart end"
}

case "$1" in
    start|stop|restart)
        $1
        ;;
    force-reload)
        restart
        ;;
    status)
        status $prog
        ;;
    try-restart|condrestart)
        if status $prog >/dev/null ; then
            restart
        fi
        ;;
    reload)
        action $"Service ${0##*/} does not support the reload action: " /bin/false
        exit 3
        ;;
    *)
	echo $"Usage: $0 {start|stop|status|restart|try-restart|force-reload}"
	exit 2
	;;
esac

