Sophie

Sophie

distrib > Mandriva > 2010.1 > x86_64 > media > main-release > by-pkgid > 2bcbda76fd41ca35be7beea090157d58 > files > 2

ipmiutil-2.6.3-1mdv2010.1.x86_64.rpm

#! /bin/sh
#
# ipmi_port         
#
# chkconfig: 345 91 07
# description: ipmi_port reserves the IPMI RMCP port 623 from portmap
#		which prevents portmap from trying to use port 623.
# 		This script also applies any saved IPMI thresholds, and
#		copies the bmclanpet.mib to where SNMP can find it.
#		It is recommended that this service be started for
#		all systems with ipmiutil that also have portmap.
#
### BEGIN INIT INFO
# Provides: ipmi_port
# Required-Start: $localfs $network
# Required-Stop:  $localfs $network
# Default-Start:  
# Default-Stop:   
# Short-Description: ipmi_port reserves the RMCP port from portmap
# Description: ipmi_port is used to reserve the RMCP port from portmap
### END INIT INFO
#
#if [ -f /etc/init.d/functions ]; then
# Source function library.
#. /etc/init.d/functions
#fi

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

getpid () {
    # This is messy if the parent script is same name as $1
    p=`ps -ef |grep "$1" |grep -v grep |awk '{print $2}'`
    echo $p
}

start()
{
	gprintf "Starting %s: " "$name"
	echo
	retval=1
	PID=0
	if [ -f $thresh ]
	then
	   # apply saved IPMI sensor thresholds, if any
	   sh $thresh
	fi
	if [ -d ${mibdir} ]
	then
	   # put bmclanpet MIB where SNMP can find it
	   cp -f $datadir/bmclanpet.mib ${mibdir}/BMCLAN-PET-MIB.txt
	fi

	dpc=`getpid dpcproxy`
	if [ "x${dpc}" != "x" ]
	then
	   gprintf "%s: dpcproxy is already running on port 623,\n" "$name"
	   gprintf "so %s is not needed.\n" "$name"
	   retval=6
	else
	   [ -x $portmap ] || exit 6
	   [ -x $prog ] || exit 5
	   $prog -b
	   retval=$?
	   if [ $retval -eq 0 ]; then
	        PID=`getpid "$prog -b"`
		echo $PID >$lockfile
	   fi
	fi
	echo
	return $retval
}

stop()
{
	gprintf "Stopping %s: " "$name"
	echo
        retval=1
	if [ -f $lockfile ]; then
           p=`cat $lockfile`
           if [ "x$p" = "x" ]; then
	        p=`getpid "$prog -b"`
           fi
           if [ "x$p" != "x" ]; then
                kill $p
                retval=$?
           fi
        fi
	echo
	if [ -d ${mibdir} ]; then
	   rm -f ${mibdir}/BMCLAN-PET-MIB.txt
	fi
	[ $retval -eq 0 ] && rm -f $lockfile
	return $retval
}

restart()
{
	stop
	start
}

rh_status() {
    if [ -f $lockfile ]; then
        p=`cat $lockfile`
        if [ "x$p" != "x" ]; then
           pid=`getpid $p`
           if [ "x$pid" != "x" ]; then
              gprintf "%s (pid %s) is running...\n" "$name" "$pid"
              retval=0
           else
              gprintf "%s is dead but %s exists\n" "$name" "$lockfile"
              retval=1
	   fi
        else
           gprintf "%s %s exists but is empty\n" "$name" "$lockfile"
           retval=2
        fi
    else
        gprintf "%s is stopped\n" "$name"
        retval=3
    fi
    return $retval
}

rh_status_q() {
    rh_status >/dev/null 2>&1
}

case "$1" in
  start)
        rh_status_q && exit 0
	start
	;;
  stop)
        rh_status_q || exit 0
	stop
	;;
  status)
	rh_status 
	;;
  restart)
	restart
	;;
  reload)
        rh_status_q || exit 7
	restart
	;;
  force_reload)
	restart
	;;
  condrestart|try-restart)
	rh_status_q || exit 0
	restart
	;;
  *)
	gprintf "Usage: %s {start|stop|status|restart|condrestart|try-restart|reload|force-reload}\n" "$0"
	exit 2
esac

exit $?