#!/bin/bash
#
#
# File for automatic startup of SIGMET rvp8
#
# chkconfig: 345 96 3
# description: SIGMET RVP8 startup file

# Source function library.
. /etc/rc.d/init.d/functions
. /etc/sigmet/profile.conf
. /etc/profile.d/sigmet.sh

if [ ! -x ${install_root}/bin/rvp8 ] ; then
    echo "ERROR: ${install_root}/bin/rvp8 file missing"
    exit 0
fi

RETVAL=0

start() {
  # Execute the commands to start rvp8
    PROCESSCOUNT=$(ps -ef | grep -v grep | grep -V start | grep -cw rvp8)
    if [[ -f /var/lock/subsys/rvp8 ]] && [[ ${PROCESSCOUNT} -eq 0 ]] ; then
        rm /var/lock/subsys/rvp8
    fi

    if [ ! -f /var/lock/subsys/rvp8 ]; then
	echo -n $"Starting rvp8: "
	${install_root}/bin/rvp8 -daemon
	RETVAL=$?
	if [ $RETVAL ] ; then
	    echo_success
	    touch /var/lock/subsys/rvp8
	else
	    echo_failure
	fi
	echo
    fi
    return $RETVAL
}

stop() {
    echo -n $"Stopping rvp8: "
    killproc rvp8 -TERM
    RETVAL=$?
    sleep 1 ; # Allow IPCS exit cleanups
    echo
    if [ $RETVAL ] ; then
	rm -f /var/lock/subsys/rvp8
    fi
    return $RETVAL
}


case $1 in

'start')
	start
	;;

'stop')
	stop
	;;

'restart')
        stop
        start
	;;

*)
	echo "usage: $0 {start|stop|restart}"
	;;
esac

exit $?
