#!/bin/bash
#
# EMIR
#
# chkconfig: 235 96 04
# description: EMIR

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

NAME="EMIR"

#
# Read basic configuration parameters
#
. /etc/emi/emir/startup.properties


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

start() {
	echo -n "Starting $NAME: "
	daemon --user $EMIR_USER "$START"
	RETVAL=$?
	[ $RETVAL -eq 0 ] && touch "/var/lock/subsys/$SERVICE"
	echo
	return $RETVAL
}
stop() {
	echo -n $"Stopping $NAME: "
	/sbin/runuser -s /bin/sh -c "$STOP" $EMIR_USER 
	rm -f "/var/lock/subsys/$SERVICE"
	echo
}

# See how we were called.
case "$1" in
  start)
	start
	;;
  stop)
	stop
	;;
  status)
	status -p "$PID" "$SERVICE"
	RETVAL=$?
	;;
  restart)
	stop
	start
	;;
  reload)
	echo "Reloading is not supported for this service. Use restart, if the modified configuration files are not automatically reloaded." 
	;;

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

exit $RETVAL
