#!/bin/bash
#
# File for automatic startup of Vaisala DspExport
#
# chkconfig: 345 99 02
# description: Vaisala DspExport daemon
#

### BEGIN INIT INFO
# Provides: dspexport
# Required-Start: rdasys antennad $rvp
# Required-Stop: rdasys antennad $rvp
# Default-Stop: 0 1 6
# Short-Description: Start DspExport daemon
# Description: Starts Vaisala DspExport daemon
### END INIT INFO

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

DSPEXPORT_PATH="${install_root}/bin/DspExport"

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

RETVAL=0

start() {
    # Check if atd is already running
    if [ ! -f /var/lock/subsys/dspexport ]; then
        echo -n $"Starting DspExport: "
        ${DSPEXPORT_PATH} -daemon -heartbeat
        RETVAL=$?
        if [ $RETVAL ] ; then
            echo_success
	    touch /var/lock/subsys/dspexport
        else
            echo_failure
        fi
        echo
    fi
    return $RETVAL
}

stop() {
    echo -n $"Stopping DspExport: "
    killproc DspExport -TERM
    RETVAL=$?
    echo
    if [ $RETVAL ] ; then
	rm -f /var/lock/subsys/dspexport
    fi
    return $RETVAL
}

case $1 in

'start')
	start
	;;

'stop')
	stop
	;;

'restart')
        stop
        start
	;;

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

exit $?
