#!/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: - 91 1
# description: hp SNMP Agents. 
#
#
# Following lines are in conformance with LSB 1.2 spec
### BEGIN INIT INFO
# Provides:            cpqiScsi
# Default-Start:       2 3 4 5
# Required-Start:      smad
# Required-Stop:       $syslog
# Default-Stop:        0 1 6
# Description:         starts OS helper for CPQISCSI
# Short-Description:   CPQISCSI helper
### END INIT INFO

PATH=/sbin:/usr/sbin:/bin:/usr/bin
NAME="cpqiScsi MIB Handler"
SNAME="/sbin/cpqiScsi"
RNAME="cpqiScsi"
OPTIONS=""
sname=`basename $SNAME`
SNAME_PID="/run/$sname.pid"


if [ -f /etc/sysconfig/$sname ]; then
  . /etc/sysconfig/$sname
fi
if [ -f "/etc/default/$sname" ]; then
  . /etc/default/$sname
fi
if [ -f "/lib/lsb/init-functions" ]; then
  . /lib/lsb/init-functions
fi

case "$1" in
   start)
      log_daemon_msg "Starting ""$cpqiScsi MIB Handler"":"
      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

      start-stop-daemon --quiet --start --oknodo --exec $SNAME -- $OPTIONS
      log_progress_msg " $sname"

   ;;
   stop)
      RC=0;
      log_daemon_msg "Stopping ""$cpqiScsi MIB Handler"":"
      start-stop-daemon --quiet --stop --oknodo --exec $SNAME && [ ! -f $SNAME_PID ] || rm $SNAME_PID
      log_progress_msg " $sname"

   ;;
  restart)
    log_daemon_msg "Restarting ""$cpqiScsi MIB Handler"":"
    start-stop-daemon --quiet --stop --oknodo --exec $SNAME  && [ ! -f $SNAME_PID ] || rm $SNAME_PID
    # Allow the daemons time to exit completely.
    sleep 2
        start-stop-daemon --quiet --start --exec $SNAME -- $OPTIONS
        log_progress_msg " $sname"
    ;;
  status)
    status=0
    status_of_proc $SNAME $sname || status=$?
    exit $status
    ;;
  *)
    echo "Usage: /etc/init.d/$sname {start|stop|restart|status}"
    exit 1

   ;;
   reload)
   ;;
   *)
     echo "Usage: /etc/init.d/$sname {start|stop|restart|status}"
     exit 1
esac

exit 0 
