#!/bin/sh
# $Id: ipmidetectd.init,v 1.1 2009-10-01 18:09:57 chu11 Exp $
#
# chkconfig: - 70 40
# description: ipmidetectd startup script
#
### BEGIN INIT INFO
# Provides: ipmidetectd
# Required-Start: $network $remote_fs $syslog
# Required-Stop:  $network $remote_fs $syslog
# Default-Start:  3 5
# Default-Stop:   0 1 2 6
# Short-Description: Start and stop ipmidetectd
# Description: IPMI node detection monitoring daemon
### END INIT INFO

IPMIDETECTD=/opt/local/sbin/ipmidetectd
IPMIDETECTD_CONF=/opt/local/etc/freeipmi/ipmidetectd.conf
LOCKFILE=/opt/local/var/lock/subsys/ipmidetectd

[ -f $IPMIDETECTD ] || exit 5
[ -f $IPMIDETECTD_CONF ] || exit 6

# Load Redhat or Suse appropriate libs
if [ -f /opt/local/etc/rc.d/init.d/functions ] ; then
    . /opt/local/etc/rc.d/init.d/functions
    Xstart() {
        daemon $IPMIDETECTD
        RETVAL=$?
        echo
        [ $RETVAL -eq 0 ] && touch $LOCKFILE
    }
    Xstop() {
        killproc ipmidetectd -TERM
        RETVAL=$?
        echo
        [ $RETVAL -eq 0 ] && rm -f $LOCKFILE
    }
    Xstatus() {
        status ipmidetectd
        RETVAL=$?
        return $RETVAL
    }
    Xcondrestart() {
        if test -e $LOCKFILE; then
            $0 stop
            $0 start
            RETVAL=$?
        fi
    }
    Xexit() {
        exit $RETVAL
    }
elif [ -f /opt/local/etc/rc.status ] ; then
    . /opt/local/etc/rc.status
    Xstart() {
        startproc $IPMIDETECTD
        rc_status -v
    }
    Xstop() {
        killproc -TERM $IPMIDETECTD
        rc_status -v
    }
    Xstatus() {
        echo -n "Checking for ipmidetectd: "
        checkproc $IPMIDETECTD
        rc_status -v
    }
    Xcondrestart() {
        $0 status
        if test $? = 0; then
            $0 restart
        else
            rc_reset
        fi
        rc_status
    }
    Xexit() {
        rc_exit
    }
else
    echo "Unknown distribution type"
    exit 1
fi

RETVAL=0

case "$1" in
   start)
        echo -n "Starting ipmidetectd: "
        Xstatus >/dev/null 2>&1 && exit 0
        Xstart
        ;;
  stop)
        echo -n "Shutting down ipmidetectd: "
        Xstop
        ;;
  restart)
        $0 stop
        $0 start
        RETVAL=$?
        ;;
  status)
        Xstatus
        ;;
  condrestart|try-restart|force-reload)
        Xcondrestart
        ;;
  *)
        echo "Usage: $0 {start|stop|restart|status|condrestart|try-restart|force-reload}"
        exit 2
esac
exit $RETVAL
