#!/bin/bash
#
# File for automatic startup of Vaisala dspmuxd
#
# chkconfig: 345 99 02
# description: Vaisala dspmux deamon
#
# Source function library.
. /etc/rc.d/init.d/functions
. /etc/sigmet/profile.conf
. /etc/profile.d/sigmet.sh

DSPMUXD_PATH="${install_root}/bin/dspmuxd"

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

RETVAL=0

start() {
    # Check if it is already running
    if [ ! -f /var/lock/subsys/dspmuxd ]; then
        echo -n $"Starting dspmuxd: "
        ${DSPMUXD_PATH} -daemon -heartbeat -out_host=192.168.45.208,192.168.45.219 -switch=60.0,40.0,30.0,20.0 -zcal=-17.0,-15.0,-14.0,-12.0 -res=125,125,125,125
        RETVAL=$?
        if [ $RETVAL ] ; then
            echo_success
	    touch /var/lock/subsys/dspmuxd
        else
            echo_failure
        fi
        echo
    fi
    return $RETVAL
}

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

case $1 in

'start')
	start
	;;

'stop')
	stop
	;;

'restart')
        stop
        start
	;;

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

exit $?
