#!/bin/sh
#
# ipmievd daemon to send events to syslog
#
# chkconfig:	2345 80 30
#
# description: ipmievd daemon to send events to syslog
#
# Description: Start ipmievd to read events from BMC and
#	           log them to syslog.
#	           Events correspond to hardware faults,
#	           state transitions such as power on and off, and sensor
#	           readings such as temperature, voltage and fan speed that
#	           are abnormal.
#
# processname: ipmievd
# config:      /etc/sysconfig/ipmievd
#
# $Id$

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

IPMIEVD_OPTIONS=
IPMIEVD_INTERFACE=open

# Get service config - may override defaults
[ -f /etc/sysconfig/ipmievd ] && . /etc/sysconfig/ipmievd

start() {
	# Check if the service is already running?
	if [ -f /var/lock/subsys/ipmievd ]; then
		msg_already_running "ipmievd"
		return
	fi

	msg_starting "ipmievd"
	daemon /usr/sbin/ipmievd -I $IPMIEVD_INTERFACE $IPMIEVD_OPTIONS
	RETVAL=$?
	[ $RETVAL -eq 0 ] && touch /var/lock/subsys/ipmievd
}

stop() {
	if [ ! -f /var/lock/subsys/ipmievd ]; then
		msg_not_running "ipmievd"
		return
	fi

	# Stop daemons.
	msg_stopping "ipmievd"
	killproc ipmievd
	rm -f /var/lock/subsys/ipmievd
}

condrestart() {
	if [ ! -f /var/lock/subsys/ipmievd ]; then
		msg_not_running "ipmievd"
		RETVAL=$1
		return
	fi

	stop
	start
}

RETVAL=0
# See how we were called.
case "$1" in
  start)
	start
	;;
  stop)
	stop
	;;
  restart)
	stop
	start
	;;
  try-restart)
	condrestart 0
	;;
  force-reload)
	condrestart 7
	;;
  status)
	status ipmievd
	RETVAL=$?
	;;
  *)
	msg_usage "$0 {start|stop|restart|try-restart|reload|force-reload|status}"
	exit 3
esac

exit $RETVAL
