#!/bin/bash
#
# UNICORE Virtual Organizations Server
#
# chkconfig: 235 97 03
# description:  UNICORE Virtual Organizations Server

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

. /etc/sysconfig/unicore

DIR="$UNICORE_UVOS"
NAME="UVOS"

#This must be equal to the file name
SERVICE=unicore_uvos

start() {
        echo -n "Starting $NAME: "
        daemon --user $UNICORE_USER "$DIR"/bin/startServer.sh
        RETVAL=$?
        [ $RETVAL -eq 0 ] && touch "/var/lock/subsys/$SERVICE"
        echo
        return $RETVAL
}
stop() {
	echo -n $"Stopping $NAME: "
	runuser - $UNICORE_USER -c "$DIR/bin/stopServer.sh"
    rm -f "/var/lock/subsys/$SERVICE"
	echo
}

# See how we were called.
case "$1" in
  start)
	start
	;;
  stop)
	stop
	;;
  status)
        status -p "$DIR/LAST_PID" "$SERVICE"
	RETVAL=$?
	;;
  restart)
	stop
	start
	;;
  *)
	echo $"Usage: $0 {start|stop|status|restart|help}"
	exit 1
esac

exit $RETVAL
