#! /bin/sh
#
# ipmi_port         
#
# chkconfig: 2345 91 07
# description: ipmi_port to reserve the IPMI RMCP port 623 from portmap
#
### BEGIN INIT INFO
# Provides: ipmi_port
# Required-Start: $network
# Default-Start:  3 4 5
# Default-Stop:   0 1 2 6
# Description: ipmi_port is used to reserve the RMCP port from portmap
### END INIT INFO
#
# Source function library.
# . /etc/init.d/functions

name=ipmi_port
progdir=/usr/sbin
datadir=/usr/share/ipmiutil
prog="$progdir/$name"
portmap=/etc/init.d/portmap
# This threshold script could be created by ipmiutil sensor -p ...
thresh="$datadir/thresholds.sh"

ps -ef |grep -v grep | grep dpcproxy  >/dev/null
if [ $? -eq 0 ]
then
    gprintf "%s: dpcproxy is already running on port 623,\n" "$name"
    gprintf "so ipmi_port is not needed.\n"
    exit 1
fi

case "$1" in
  start)
	gprintf "Starting %s: " "$name"
	echo
	if [ -f $thresh ]
	then
	   # apply saved sensor thresholds, if any
	   sh $thresh
	fi
	if [ -x $portmap ]
	then
	   $prog -b
	fi
	RETVAL=$?
	;;
  stop)
	gprintf "Stopping %s: " "$name"
	echo
	RETVAL=1
        rpid=`ps -ef |grep $name |grep -v grep |awk '{print $2}'`
        if [ "${rpid}" != "" ]
        then
           kill $rpid
	   RETVAL=$?
        fi
	;;
  *)
	gprintf "Usage: %s {start|stop}\n" "$0"
	exit 1
esac
