#!/bin/sh
#
# irqbalance       Start/Stop irq balancing daemon
#
# chkconfig: - 13 87
# description: The irqbalance daemon will distribute interrupts across  \
#              the cpus on a multiprocessor system with the purpose of \
#              spreading the load. \
# processname: irqbalance
# config: /etc/sysconfig/irqbalance
# pidfile: /var/run/irqbalance.pid

### BEGIN INIT INFO
# Provides:          irqbalance
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start IRQ balancer
# Description:       Enable IRQ balancer.
### END INIT INFO

# Do not load RH compatibility interface.
WITHOUT_RC_COMPAT=1

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

#PIDFILE=/var/run/irqbalance.pid
LOCKFILE=/var/lock/subsys/irqbalance
IRQBALANCE_BIN=/usr/sbin/irqbalance
RETVAL=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()
{
	start_daemon --lockfile "$LOCKFILE" --expect-user root -- $IRQBALANCE_BIN $ONESHOT
	RETVAL=$?
	return $RETVAL
}

stop()
{
	stop_daemon --lockfile "$LOCKFILE" --expect-user root -- $IRQBALANCE_BIN
	RETVAL=$?
	return $RETVAL
}

restart()
{
	stop
	start
}

# See how we were called.
case "$1" in
	start)
		start
		;;
	stop)
		stop
		;;
	restart)
		restart
		;;
	condstop)
		if [ -e "$LOCKFILE" ]; then
			stop
		fi
		;;
	condrestart)
		if [ -e "$LOCKFILE" ]; then
			restart
		fi
		;;
	status)
		status --expect-user root -- $IRQBALANCE_BIN
		RETVAL=$?
		;;
	*)
		msg_usage "${0##*/} {start|stop|restart|condstop|condrestart|status}"
		RETVAL=1
esac

exit $RETVAL


