#!/bin/bash
#
# chkconfig:    345 31 69
# description:  Balance IRQs
#
### BEGIN INIT INFO
# Provides:          nginx httpd
# Required-Start:    $syslog $remote_fs
# Required-Stop:     $syslog $remote_fs
# Default-Start:     3 5
# Default-Stop:      0 1 2 4 6
# Short-Description: Balance IRQs
# Description:       BIRQ stands for Balance IRQs. This is software to balance
#       interrupts between CPUs on Linux while high load.
### END INIT INFO

BIRQ_BIN=/usr/sbin/birq
BIRQ_PID=/var/run/birq.pid

if [ -r /etc/rc.status ]
then
  source /etc/rc.status
  START="/sbin/startproc"
  STATUS="/sbin/checkproc"
  SUCCESS="echo \$rc_done"
  FAILURE="echo \$rc_failed"
else
  source /etc/rc.d/init.d/functions
  START="daemon"
  STATUS="status"
  SUCCESS="success; echo"
  FAILURE="failure; echo"
fi

[ -r /etc/sysconfig/birq ] && source /etc/sysconfig/birq

test -f "${PROXIMITY_CONFIG_FILE}" && ARGS="${ARGS} --pxm=${PROXIMITY_CONFIG_FILE}"
test -n "${THRESHOLD}"             && ARGS="${ARGS} --threshold=${THRESHOLD}"
test -n "${LOADLIMIT}"             && ARGS="${ARGS} --load-limit=${LOADLIMIT}"
test -n "${INTSHORT}"              && ARGS="${ARGS} --short-interval=${INTSHORT}"
test -n "${INTLONG}"               && ARGS="${ARGS} --long-interval=${INTLONG}"
test -n "${STRATEGY}"              && ARGS="${ARGS} --strategy=${STRATEGY}"

RETVAL=0

case "$1" in
  start)
    echo -n "Starting birq: "
    ${START} ${BIRQ_BIN} --pid=${BIRQ_PID} ${ARGS}
    RETVAL=$?
    ;;
  stop)
    echo -n "Stopping birq: "
    killproc ${BIRQ_BIN} > /dev/null 2>&1
    RETVAL=$?
    ;;
  restart)
    $0 stop
    $0 start
    unset RETVAL
    ;;
  reload)
    killproc -HUP ${BIRQ_BIN} > /dev/null 2>&1
    RETVAL=$?
    ;;
  status)
    echo -n "Status of birq: "
    ${STATUS} ${BIRQ_BIN} > /dev/null 2>&1
    RETVAL=$?
    ;;
  *)
    echo "Usage: $0 {start|stop|status|restart|reload}"
    exit 1
    ;;
esac
[ -z ${RETVAL} ] && exit
[ ${RETVAL} -eq 0 ] && eval "${SUCCESS}" || eval "${FAILURE}"
exit ${RETVAL}
