#!/bin/bash
#
# hpessad        This starts and stops hpessa.
#
# chkconfig: - 99 99
# description: hpessad
#	       hpessa allows configuration of HPE RAID storage
#
# processname: /usr/sbin/hpessa


PATH=/sbin:/bin:/usr/bin:/usr/sbin

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

RETVAL=0
prog="hpessa"

start(){
    [ -f /usr/sbin/hpessa ] || exit 5
    # this is suitable way considering SELinux is guarding write 
    # access to PID file
	[ $EUID -eq 0 ] || exit 4

   # make sure SMH is running
   [ -f /etc/init.d/hpsmhd ] || exit 3
   /etc/init.d/hpsmhd status > /dev/null 2>&1
   if [ "$?" -ne "0" ]
   then
      /etc/init.d/hpsmhd start
   fi

    echo -n $"Starting $prog: "

    daemon $prog -start 
    RETVAL=$?
    echo
    return $RETVAL
}

stop(){
    [ -f /usr/sbin/hpessa ] || exit 5
    # this is suitable way considering SELinux is guarding write 
    # access to PID file
	[ $EUID -eq 0 ] || exit 4

    echo -n $"Stopping $prog: "
    /usr/sbin/hpessa -stop
    RETVAL=$?
    echo
    return $RETVAL
}

restart(){
    stop
    start
}

# See how we were called.
case "$1" in
    start)
	start
	RETVAL=$?
	;;
    stop)
	stop
	RETVAL=$?
	;;
    status)
	status $prog
	RETVAL=$?
	;;
    restart)
	restart
	RETVAL=$?
	;;
    *)
	echo $"Usage: $0 {start|stop|restart}"
	RETVAL=2
esac

exit $RETVAL
