#!/bin/bash
#
# File for automatic startup of tsimport (Time Series import utility)
#
# chkconfig: 345 97 2
# description: SIGMET tsimport utility
#
# Source function library.
. /etc/rc.d/init.d/functions

#-----------USAGE NOTES
# TSEXPORT
#
# tsimport can take the following options:
# tsimport -port -debug -daemon
#
# SIGMET RECOMMENDS THE FOLLOWING PORTS:
#   RVP8:
#     TSEXPORT: 30780
#     TSIMPORT: 30781
#
#   ARCHIVE HOST:
#     TSEXPORT: 30781
#     TSIMPORT: 30780
#
PORT="30781"

# NOTE: THE PORTS FOR EXPORT AND IMPORT HAVE TO MATCH (CONNECT)
#       BETWEEN THE RVP8 AND THE ARCHIVE HOST
#
# tsimport should be used in the following manner: 
#    
#	tsimport -port 30781
#

TSIMPORT_PATH="/usr/sigmet/bin/rda/tsimport"

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

start(){
  # Execute the commands to start tsimport
    if [ ! -f /var/lock/subsys/tsimport ]; then
	echo -n $"Starting tsimport: "
	su - operator -c "${TSIMPORT_PATH} -port:${PORT} -daemon"
	RETVAL=$?
	if [ $RETVAL ] ; then
	    echo_success
	    touch /var/lock/subsys/tsimport
	else
	    echo_failure
	fi
	echo
    fi
    return $RETVAL
}

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

case $1 in

'start')
	start
	;;

'stop')
	stop
	;;

'restart')
        stop
        start
	;;

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

exit $?
exit RETVAL

