#!/bin/bash
#
# XUUDB
#
### BEGIN INIT INFO
# Provides:          unicore-xuudb
# 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 XUUDB
### END INIT INFO

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


UNICORE_USER=unicore
NAME="UNICORE XUUDB"
START="/usr/sbin/unicore-xuudb-start"
STOP="/usr/sbin/unicore-xuudb-stop"
LASTPID="/var/run/unicore/xuudb.pid"

#This must be equal to this file name
SERVICE=unicore-xuudb

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

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 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
