#!/bin/bash
#
# UNICORE Virtual Organizations Server
### BEGIN INIT INFO
# Provides:          unicore-uvos-server
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start daemon at boot time
# Description:       UNICORE Virtual Organizations Server
### END INIT INFO



UNICORE_USER="unicore"
UNICORE_UVOS=/usr/sbin

# Source function library.
. /lib/lsb/init-functions

#. /etc/sysconfig/unicore

DIR="$UNICORE_UVOS"
START="$DIR/unicore-uvos-server-start"
STOP="$DIR/unicore-uvos-server-stop"
NAME="UVOS"
LASTPID=/var/run/unicore/uvos-server.pid

#This must be equal to the file name
SERVICE=unicore-uvos-server

start() {
	log_daemon_msg "Starting $NAME"
        start-stop-daemon --start --chuid $UNICORE_USER --exec "$START"
        RETVAL=$?
        [ $RETVAL -eq 0 ] && touch "/var/lock/$SERVICE"
        log_end_msg $RETVAL
        echo
        return $RETVAL

}
stop() {
	 log_daemon_msg "Stopping $NAME"
         echo
         su $UNICORE_USER -p "$STOP"
         log_end_msg $?
         rm -f "/var/lock/$SERVICE"
         echo

}

status(){
	 if [ -a "$LASTPID" ]; then
                 status_of_proc -p "$LASTPID" "$SERVICE"
         else
                 log_failure_msg "$SERVICE is not running"
         fi
}

# See"$DIR/unicore-uvos-server-start how we were called.
case "$1" in
  start)
	start
	;;
  stop)
	stop
	;;
  status)
	status
	;;
  restart)
	stop
	start
	;;
  force-reload)
        ;;

  *)
	echo $"Usage: $0 {start|stop|status|restart|force-reload|help}"
	exit 1
esac

exit $RETVAL
