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

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

NAME="UNICORE Registry"

#This must be equal to this file name
SERVICE=unicore-registry
UNICORE_USER=unicore
START=/usr/sbin/unicore-registry-start.sh
STOP=/usr/sbin/unicore-registry-stop.sh
LASTPID=/var/run/unicore/registry.pid

# Source sysconfig file
[ -f /etc/sysconfig/$SERVICE ] && . /etc/sysconfig/$SERVICE

start() {
	echo -n "Starting $NAME: "
	daemon --user $UNICORE_USER "$START"
	RETVAL=$?
	[ $RETVAL -eq 0 ] && touch "/var/lock/subsys/$SERVICE"
	echo
	return $RETVAL
}
stop() {
	echo -n $"Stopping $NAME: "
	runuser -s /bin/sh -c "$STOP" $UNICORE_USER 
	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
	;;
  *)
	echo $"Usage: $0 {start|stop|status|restart|help}"
	exit 1
esac

exit $RETVAL
