#!/bin/sh
#
# Wiper dog  This shell script takes care of starting and stopping
#               the wiper dog system.
#
# chkconfig: - 64 36
# description: Wiper dog database monitoring system.
# processname: startWiperdog.sh
# config:
# pidfile: /home/luvina/wiperdog/wiperdog.pid

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

WIPERDOGHOME=
if [ "$WIPERDOGHOME" = "" ];then
	echo "Error: The 'WIPERDOGHOME' is not set, exitting..."
	exit 2
fi

# Source networking configuration.
#. /etc/sysconfig/network
execCmd=${WIPERDOGHOME}/bin/startWiperdog.sh
lockFile=${WIPERDOGHOME}/var/run/wiperdog.lck
pidiFile=${WIPERDOGHOME}/var/run/wiperdog.pid

start(){
    [ -x "$execCmd" ] || exit 5
    # check to see if it's already running
    if [ -e "$lockFile" ]; then
        # already running, do nothing
        echo  "Wiperdog is already running."
        ret=0
    else
        /bin/sh "$execCmd" > /dev/null 2>&1 &
        /bin/touch "$lockFile"
        output=`ps -ef | grep Dfelix.home|grep java`
        set -- $output
        echo "Wiperdog started. "
    fi
}
debug(){
    [ -x "$execCmd" ] || exit 5
    # check to see if it's already running

    if [ -e "$lockFile" ]; then
        # already running, do nothing
        echo "Wiperdog is already running."
        ret=0
    else
        /bin/sh "$execCmd" 2>&1 &
        /bin/touch "$lockFile"
        output=`ps -ef | grep Dfelix.home|grep java`
        set -- $output
        echo "Wiperdog started. "
    fi
}
stop(){
    [ -x $stopCmd ] || exit 5
    # check to see if it's already running

    if [ -x "$lockFile" ]; then
        # not running, do nothing
        echo "Wiperdog is not running."
        ret=0
    else
        output=`ps -ef | grep Dfelix.home|grep java`
        set -- $output
        echo "Stoping Wiperdog..."
        /bin/kill -9 $2
        /bin/rm -f "$lockFile"
    fi
}

status(){
    if [ -e "$lockFile" ]; then
        # already running, do nothing
        echo "Wiperdog is running..."
    else
        echo "Wiperdog has been stopped..."
    fi

}

# See how we were called.
case "$1" in
  start)
    start
    ;;
  debug)
    debug
    ;;
  stop)
    stop
    ;;
  status)
    status
    ;;
  restart)
    stop
    start
    ;;
  *)
    echo $"Usage: $0 {start|debug|stop|status|restart}"
    exit 2
esac

exit $?