#!/bin/bash
#
#
# File for automatic startup of Vaisala rvp900
#
# chkconfig: 345 96 3
# description: Vaisala RVP900 startup file

# Source function library.
. /etc/rc.d/init.d/functions
. /etc/sigmet/profile.conf
. ${install_root}/config_template/LINUX/etc/profile.d/sigmet.sh

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

RETVAL=0

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

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

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


case $1 in

'start')
	start
	;;

'stop')
	stop
	;;

'restart')
        stop
        start
	;;

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

exit $?
