#! /bin/bash
#
# irqbalance       Start/Stop irq balancing daemon
#
# chkconfig: 345 13 87
# description: The irqbalance daemon will distribute interrupts across  \
#              the cpu's on a multiprocessor system with the purpose of \
#              spreading the load. \
# processname: irqbalance

# config: /etc/sysconfig/irqbalance
# pidfile: /var/run/irqbalance.pid

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

RETVAL=0

# See how we were called.
  
prog="irqbalance"

[ -f /usr/sbin/irqbalance ] || exit 0

# fetch configuration if it exists
# ONESHOT=yes says to wait for a minute, then look at the interrupt
# load and balance it once; after balancing exit and do not change
# it again.
# The default is to keep rebalancing once every 10 seconds.
ONESHOT=
[ -f /etc/sysconfig/irqbalance ] && . /etc/sysconfig/irqbalance
case "$ONESHOT" in
        y*|Y*|on) ONESHOT=--oneshot ;;
        *) ONESHOT= ;;
esac
		

start() {
	# Check if the machine has more than two CPUs/cores
	echo -n $"Starting $prog: "
	if [ $(/usr/bin/getconf _NPROCESSORS_ONLN) -ge 2 ] ; then
	    daemon /usr/sbin/irqbalance $ONESHOT
	else
	    passed $"irqbalance: no multiprocessors found, skipped"
	    false
	fi
	RETVAL=$?
	echo
	[ $RETVAL -eq 0 ] && touch /var/lock/subsys/irqbalance
	return $RETVAL
}

stop() {
	echo -n $"Stopping $prog: "
	if [ -z "`pidofproc $prog`" ]; then
		passed $"irqbalance is not running, skipped"
		true
	else
		killproc irqbalance
	fi
	RETVAL=$?
	echo
	[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/irqbalance
	return $RETVAL
}	

rhstatus() {
	status irqbalance
}	

restart() {
  	stop
	start
}	


case "$1" in
  start)
  	start
	;;
  stop)
  	stop
	;;
  restart)
  	restart
	;;
  reload)
  	restart
	;;
  status)
  	rhstatus
	;;
  condrestart)
  	[ -f /var/lock/subsys/irqbalance ] && restart || :
	;;
  *)
	echo "Usage: $0 {start|stop|status|reload|restart|condrestart}"
	exit 1
esac

exit $?

