#!/bin/bash
#
# chkconfig: 2345 38 1
# description: Initialize server for backups
# processname: backup_server
#
#

#set -x

. /etc/init.d/functions

start() {
    echo "Backup Server starting..."
    echo "running lsi_settings to set any misc lsi settings: "
    if /opt/eig_linux/bin/lsi_settings background >/dev/null
    then
      echo_success ; echo
    else
      echo_failure ; echo
    fi
    for i in eth{0..10}
    do
      if /sbin/ethtool -i $i |grep -q ixgbe
      then
        echo "set $i ntuple on              "
        if /sbin/ethtool -K $i ntuple on
        then
           echo_success ; echo
        else
           echo_failure ; echo
        fi
        echo "set $i lro off              "
        if /sbin/ethtool -K $i lro off
        then
           echo_success ; echo
        else
           echo_failure ; echo
        fi
        echo -n "set irq affinity for $i:      "
        if /opt/eig_linux/bin/set_irq_affinity.sh $i >/dev/null
        then
           echo_success ; echo
        else
           echo_failure ; echo
        fi
      fi
    done
    for i in /sys/block/sd* 
    do
      echo -n "setting 1024 queuedepth for $i "
      if echo 1024 >$i/queue/nr_requests
      then
         echo_success ; echo
      else
         echo_failure ; echo
      fi
    done                                                                                                                                                                 
    WHO=$REALUSER
    if [ "z$WHO" == "z" ]
    then
        WHO=system
    fi
    (nohup /usr/bin/wget --timeout=1 --tries=1 -O /dev/null "http://74.220.198.194/cgi-bin/logger.cgi?who=$WHO&what=bh-backup-init&data=service,start") >/dev/null 2>/dev/null &
    touch /var/lock/subsys/backup_server
    return 0
}

stop() {
    echo "Backup Server stopping..."
    WHO=$REALUSER
    if [ "z$WHO" == "z" ]
    then
        WHO=system
    fi
    nohup /usr/bin/wget --timeout=1 --tries=1 -O /dev/null "http://74.220.198.194/cgi-bin/logger.cgi?who=$WHO&what=bh-backup-init&data=service,stop" >/dev/null 2>/dev/null &
    rm -f /var/lock/subsys/backup_server
    return 0
}

case "$1" in
    start)
        start
        ;;
    stop)
        stop
        ;;
    *)
    echo "Usage:  {start}"
    exit 1
    ;;
esac
exit $?

