#! /bin/sh
#
# chkconfig: 2345 80 30
# description: Starts and stops the End Point Operations Management.
#
# /etc/init.d/epops-agent
#
### BEGIN INIT INFO
# Provides:          epops-agent
# Required-Start:    $network
# X-UnitedLinux-Should-Start: $time 
# Required-Stop:     
# X-UnitedLinux-Should-Stop: 
# Default-Start:     3 5
# Default-Stop:      0 1 2 6
# Short-Description: epops-agent init
# Description:       Starts End Point Operations Management, located by default in
#		/opt/epops/epops-agent directory.
### END INIT INFO

if [ -f /etc/default/epops-agent ] ; then
    . /etc/default/epops-agent
else
    echo "export HQ_JAVA_HOME=$JAVA_HOME"> /etc/default/epops-agent
    . /etc/default/epops-agent
fi

AGENT_INSTALL_DIR=/opt/epops
if [ ! -z "$EPOPS_AGENT_HOME" ] ;  then
    # Use custom install directory if specified
    AGENT_INSTALL_DIR=$EPOPS_AGENT_HOME
fi

RUN_AS_USER=epops
if [ ! -z "$EPOPS_SHELL" ]; then
    AGENT_CTL="su $RUN_AS_USER -s $EPOPS_SHELL $AGENT_INSTALL_DIR/epops-agent/bin/ep-agent.sh"
else
    AGENT_CTL="su $RUN_AS_USER -s $AGENT_INSTALL_DIR/epops-agent/bin/ep-agent.sh"
fi

case "$1" in
  start)
 $AGENT_CTL start
;;
  stop)
 $AGENT_CTL stop
;;
  restart)
 $AGENT_CTL restart
;;
 status)
 $AGENT_CTL status
;;
  *)
    echo "Usage: $0 {start|stop|restart|status}"
    exit 1
  ;;
esac

