#!/bin/bash
#
# (c) Copyright 2011-2016 Hewlett Packard Enterprise Development Company, L.P.
#
# See "man chkconfig" for information on next two lines (Red Hat only)
# chkconfig: - 90 1
# description: BMC AgentX proxy. 
#
#
# Following lines are in conformance with LSB 1.2 spec
### BEGIN INIT INFO
# Provides:            mr_cpqScsi
# Default-Start:       2 3 4 5
# Required-Start:      $network
# Required-Stop:       $network $syslog
# Default-Stop:        0 1 6
# Description:         starts AHS Logger 
# Short-Description:   AHS logger daemon helper
### END INIT INFO

PATH=/sbin:/usr/sbin:/bin:/usr/bin
NAME="Mega Raid cpqScsi MIB Handler"
SNAME="/sbin/mr_cpqScsi"
OPTIONS=""
sname=`basename $SNAME`
pidfile=/var/run/${sname}.pid

if [ -f /etc/sysconfig/mr_cpqScsi ]; then
  . /etc/sysconfig/mr_cpqScsi
fi
if [ -f "/etc/default/mr_cpqScsi" ]; then
  . /etc/default/mr_cpqScsi
fi
if [ -f "/etc/rc.d/init.d/functions" ]; then
  . /etc/rc.d/init.d/functions
elif [ -f "/lib/lsb/init-functions" ]; then
  . /lib/lsb/init-functions
fi

case "$1" in
   start)
      modprobe -q pci_slot
      if [ ! -d /sys/class/cpuid ]; then
          modprobe cpuid
      fi
      if [ "$ALLOW_CORE" = "y" ]; then
        mkdir -p /var/log/cores/${sname}
        echo "/var/log/cores/%e/%p-%s-%t.core" > /proc/sys/kernel/core_pattern
        ulimit -c unlimited
      fi
      if [ -f /etc/SuSE-release ]; then
        echo -n $"Starting $sname: "
        startproc  -p $pidfile $SNAME $OPTIONS
        rc_status -v
        echo "`pidof $sname`" > $pidfile
        rc_reset
      elif [ -f /etc/debian-release ]; then
        echo done
      else
        [ -x $SNAME ] || exit 5
        echo -n $"Starting $sname: "
        if [ $UID -ne 0 ]; then
                RC=1
                failure
        else
                daemon --pidfile=$pidfile $SNAME $OPTIONS
                RC=$?
                [ $RC -eq 0 ] && touch /var/lock/subsys/$sname
        fi;
        echo
        echo "`pidof $sname`" > $pidfile
        exit $RC
      fi
   ;;
   stop)
      if [ -f /etc/SuSE-release ]; then
        echo -n "Shutting down $sname:"
        killproc -t 10 -p $pidfile $SNAME
        rc_status -v ; rc_reset
      elif [ -f /etc/debian-release ]; then
        echo done
      else
        RC=0;
        echo -n $"Stopping $sname: "
        if [ $UID -ne 0 ]; then
                RC=1
                failure
        else
                killproc -p $pidfile $SNAME
                RC=$?
                [ $RC -eq 0 ] && rm -f /var/lock/subsys/$sname
        fi;
        echo
        exit $RC
      fi
   ;;
   reload)
   ;;
   restart)
      $0 stop
      sleep 5
      $0 start
   ;;
   status)
     if [ -f /etc/SuSE-release ]; then
        echo -n "Checking for service $sname:"
        checkproc $SNAME
        rc_status -v
    elif [ -f /etc/debian-release ]; then
        echo done
    else
      status $sname
      RC=$?
      exit $RC
    fi
   ;;
   *)
     echo "Usage: /etc/init.d/${sname} {start|stop|restart|status}"
     exit 1
esac

exit 0 
