#! /bin/sh
# Copyright (c) 1995-2002 SuSE Linux AG, Nuernberg, Germany.
# All rights reserved.
#
# /etc/init.d/irqbalance
#   and its symbolic link
# /(usr/)sbin/rcirqbalance
#
### BEGIN INIT INFO
# Provides:          irqbalance
# Required-Start:    
# X-UnitedLinux-Should-Start: 
# Required-Stop:     
# X-UnitedLinux-Should-Stop: 
# Default-Start:     1 2 3 5
# Default-Stop:      0 6
# Short-Description: irqbalance daemon providing irq balancing on MP-machines
# Description:       Start irqbalance to allow interrrupt balancing over multiple CPUs
#	             usually all irqs are handled by cpu0, this daemon dynamcally 
#	             uses all cpus for the irqs
#	
#	
#	
### END INIT INFO

# Check for missing binaries (stale symlinks should not happen)
IRQBALANCE_BIN=/usr/sbin/irqbalance
test -x $IRQBALANCE_BIN || exit 5
NUM_CPU=`/usr/bin/getconf _NPROCESSORS_ONLN`
PHYS=$(grep "physical id" /proc/cpuinfo  | sort | uniq | wc -l)
PROC=$(grep -c processor /proc/cpuinfo)

. /etc/rc.status

# Reset status of this service
rc_reset

case "$1" in
    start)
	echo -n "Starting irqbalance "
	if [ $PHYS -gt 1 -o \( $PROC -gt 1 -a $PHYS -eq 0 \) ] ; then
	    startproc $IRQBALANCE_BIN
	    # Remember status and be verbose
	    rc_status -v
	else
	    rc_status -u
	fi
	;;
    stop)
	echo -n "Shutting down irqbalance "
	killproc -TERM $IRQBALANCE_BIN

	# Remember status and be verbose
	rc_status -v
	;;
    try-restart)
	$0 status >/dev/null &&  $0 restart

	# Remember status and be quiet
	rc_status
	;;
    restart)
	$0 stop
	$0 start

	# Remember status and be quiet
	rc_status
	;;
    force-reload|reload)
	echo -n "Reload service irqbalance "
	if [ $PHYS -gt 1 -o \( $PROC -gt 1 -a $PHYS -eq 0 \) ] ; then
		## if it supports it:
	    killproc -HUP $IRQBALANCE_BIN
	    #touch /var/run/irqbalance.pid
	    rc_status -v
	else
	    rc_status -u
	fi
	;;
    status)
	echo -n "Checking for service irqbalance "
	checkproc $IRQBALANCE_BIN
	rc_status -v
	;;
    probe)
	;;
    *)
	echo "Usage: $0 {start|stop|status|try-restart|restart|force-reload|reload|probe}"
	exit 1
	;;
esac
rc_exit
