#!/bin/bash
#

#
# iris    File for automatic startup of SIGMET IRIS, on Linux platforms
#
# chkconfig: 345 99 0
# description: SIGMET IRIS startup file

# Source function library.
. /etc/rc.d/init.d/functions

#PATH=/usr/sbin:/usr/bin:/sbin:/bin

if [ ! -x /usr/sigmet/bin/siris ] ; then
    echo "ERROR: /usr/sigmet/bin/siris file missing"
    exit 0
fi
if [ ! -x /usr/sigmet/bin/qiris ] ; then
    echo "ERROR: /usr/sigmet/bin/qiris file missing"
    exit 0
fi

RETVAL=0


start() {
  # Execute the commands to start iris
    if [ ! -f /var/lock/subsys/iris ] ; then
	echo -n $"Starting iris: "
	su - operator -c "/usr/sigmet/bin/siris -auto 1>/tmp/siris_out 2>/tmp/siris_err"
	RETVAL=$?
	if [ $RETVAL ] ; then
	    echo_success
	    touch /var/lock/subsys/iris
	else
	    echo_failure
	fi
	echo
    fi
    return $RETVAL
}

stop() {
  # Execute the commands to stop iris
    echo -n $"Stopping iris: "
    su - operator -c "/usr/sigmet/bin/qiris -auto"
    RETVAL=$?
    echo
    if [ $RETVAL ] ; then
	rm -f /var/lock/subsys/iris
    fi
    return $RETVAL
}


case $1 in

'start')
	start
	;;

'stop')
	stop
	;;

'restart')
	stop
	start
	;;

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

exit $?
exit RETVAL
