#!/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:
# 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
# IRQBALANCE_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.
IRQBALANCE_ONESHOT=

SourceIfNotEmpty /etc/sysconfig/irqbalance

case "$IRQBALANCE_ONESHOT" in
	y*|Y*|on) IRQBALANCE_ONESHOT=--oneshot ;;
	*) IRQBALANCE_ONESHOT= ;;
esac

start()
{
	start_daemon --lockfile "$LOCKFILE" --expect-user root -- $IRQBALANCE_BIN --pid=$PIDFILE $IRQBALANCE_ONESHOT $IRQBALANCE_ARGS
	RETVAL=$?
	return $RETVAL
}

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

restart()
{
	stop
	start
}

reload()
{
	msg_reloading irqbalance
	stop_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --expect-user root -HUP -- $IRQBALANCE_BIN
	RETVAL=$?
	return $RETVAL
}

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

exit $RETVAL


