#!/bin/sh
# /etc/init.d/videod: start video Server
#
# chkconfig: 2345 10 90
#
PATH=/bin:/usr/bin:/sbin:/usr/sbin

PATHFUL_IPMIINIT="/usr/local/bin/IPMIMain"

#REVISIT ### Disable the IPMI stack for bring up
#exit 0

PLATFORM=$(cat /proc/platform)

if [ $PLATFORM == "Carnegie" -o $PLATFORM == "Reference" -o $PLATFORM == "Absolut"  -o $PLATFORM == "RazorM" -o $PLATFORM == "RazorL" -o $PLATFORM == "RazorS" ] 
then 
	ln -sf /usr/local/lib/$PLATFORM-libPAR.so.1.0  /usr/local/lib/libPAR.so.1.0
else 
	echo "*** ENTER CORRECT PLATFORM ID FOR IPMI STACK TO START : NO PLATFORM ID SPECIFIED ***"  
	exit 0
fi 

test -f /usr/local/bin/IPMIMain || exit 0

# Options for start/restart the daemons
#
#


case "$1" in
  start)
    IPMIPid=$(pidof IPMIMain)
    if [ -z "$IPMIPid" ]
    then
        echo -n "Starting IPMI Stack: IPMIMain "
        #we just do ldconfig since ipmi may be started very early on
        # Run ldconfig - Ractrends Specific
        if [ -x /sbin/ldconfig ]
        then
	        echo "Creating /var/ld.so.cache to which /etc/ld.so.cache is linked..."
	        /sbin/ldconfig -C /var/ld.so.cache
        fi
        /usr/local/bin/IPMIMain &
        if [ -f "/var/run/RazorS" ] || [ -f "/var/run/RazorM" ]  ; then
            /usr/local/bin/acp_init_expander_thresholds.sh &
        fi
   #    start-stop-daemon --start --quiet --exec $PATHFUL_IPMIINIT
        echo "."
    fi
    ENVMGR=$(pidof env_mgr)
    if [ -n "$ENVMGR" ]
    then
        killall env_mgr
    fi
    ;;
  stop)
    # stop the env_mgr sensors polling
    /usr/local/bin/envcmdtool command_query 6 2 > /dev/null
    echo -n "Stopping IPMI Stack: IPMIMain"
    killall IPMIMain
#    start-stop-daemon --stop --quiet --exec $PATHFUL_IPMIINIT
    echo "."
    ;;
    reload)
	echo -n "Reloading IPMI Stack: IPMIMain"
	echo "dont know what to do with reload right now"
#	start-stop-daemon --stop --quiet --exec $PATHFUL_IPMIINIT --signal 1
	echo "."
	;;
    force-reload)
#	$0 reload
	;;
    restart)
	echo -n "Restarting IPMI Stack: IPMIMain"
	killall IPMIMain
	/usr/local/bin/IPMIMain &
	if [ -f "/var/run/RazorS" ] || [ -f "/var/run/RazorM" ]  ; then
		/usr/local/bin/acp_init_expander_thresholds.sh &
	fi
#	start-stop-daemon --stop --quiet --oknodo --exec $PATHFUL_IPMIINIT
#	start-stop-daemon --start --quiet --exec $PATHFUL_IPMIINIT
	echo "."
	;;
   *)
    echo "Usage: /etc/init.d/ipmistack {start|stop|reload|restart|force-reload}"
    exit 1
esac

exit 0
