#!/bin/bash
#
# UNICORE TSI
#
# chkconfig: 235 96 04
# description: UNICORE TSI

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

NAME="UNICORE TSI"

#This must be equal to this file name
SERVICE=unicore-tsi
START=/usr/share/unicore/tsi_selected/bin/start_tsi
STOP=/usr/share/unicore/tsi_selected/bin/kill_tsi
LASTPID=/var/run/unicore/tsi.pid
CONF=/etc/unicore/tsi

[ -f /etc/sysconfig/$SERVICE ] && . /etc/sysconfig/$SERVICE

start() {
	echo -n "Starting $NAME: "
	"$START" $CONF
	RETVAL=$?
	[ $RETVAL -eq 0 ] && touch "/var/lock/subsys/$SERVICE"
	echo
	return $RETVAL
}
stop() {
	echo -n $"Stopping $NAME: "
	"$STOP" $CONF
	rm -f "/var/lock/subsys/$SERVICE"
	echo
}



# See how we were called.
case "$1" in
  start)
	start
	;;
  stop)
	stop
	;;
  status)
	status -p "$LASTPID" "$SERVICE"
	RETVAL=$?
	;;
  restart)
	stop
	start
	;;
  setup)
	# Setup the TSI, i.e. run Install.sh from the installation directory
	cd /usr/share/unicore/tsi
	./Install.sh "" /usr/share/unicore/tsi_selected
	;;
  *)
	echo $"Usage: $0 {start|stop|status|restart|help}"
	exit 1
esac

exit $RETVAL
