#!/bin/bash
#
# File for automatic startup of SIGMET DspExport
#
# chkconfig: 345 99 0
# description: SIGMET DspExport feature
#
# Source function library.
. /etc/rc.d/init.d/functions

DSPEXPORT_PATH="/usr/sigmet/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: "
        su - operator -c "${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 $?
exit RETVAL
