#!/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: - 51 49
# description: SMA Reverse BMC <-> AgentX proxy. 
#
#
# Following lines are in conformance with LSB 1.2 spec
### BEGIN INIT INFO
# Provides:            smad_rev
# Default-Start:       2 3 4 5 
# Default-Stop:        0 1 6
# Required-Start:      snmpd
# Required-Stop:
# Description:         starts System Management Assistant BMC Reverse Proxy
# Short-Description:   SMA Reverse proxy
### END INIT INFO

PATH=/sbin:/usr/sbin:/bin:/usr/bin
NAME="System Management Assistant Reverse Proxy Service"
SNAME="/sbin/smad_rev"
OPTIONS=""
sname=`basename $SNAME`
pidfile=/var/run/${sname}.pid

if [ -f /etc/sysconfig/smad_rev ]; then
  . /etc/sysconfig/smad_rev
fi
if [ -f "/etc/default/smad_rev" ]; then
  . /etc/default/smad_rev
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
        [ -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

   ;;
   stop)
        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
   ;;
   reload)
   ;;
   restart)
      $0 stop
      sleep 5
      $0 start
   ;;
   status)
      status $sname
      RC=$?
      exit $RC
   ;;
   *)
     echo "Usage: /etc/init.d/${sname} {start|stop|restart|status}"
     exit 1
esac

exit 0 
