#!/bin/bash

# startSNMPD
#
# Usage:
#    startSNMPD <snmpd.conf file> <pid file> <snmp agent parameters>
#
# Description:
#    This script starts the SNMP daemon for the console
#    using the snmpd.conf configuration file generated by the
#    SNMP configuration task under HMC Console Settings.
#
# Return Codes
#    0: normal script termination; no unrecoverable errors
#    1: error starting the SNMP daemon
#
# Module History
#    00  03/11/2003  P. Provost - Initial Release
#    01  11/24/2003  P. Provost - Removed setup of environment for ODT E3286
#    02  12/01/2004  M. Clark   - Added DOMAIN_SOCKET_DIR variable
#    03  10/14/2005  Schroeder  - Change parms to force logging to syslog and remove the netsnmp log rotate file
#    04  02/13/2007  Schroeder  - Use both UDP and TCP ports.

CONFFILE=$1
PIDFILE=$2
export DOMAIN_SOCKET_DIR=$3
CONSOLE_PATH=$4
PARMS=$5

# include the common hmc functions
. "$CONSOLE_PATH"hmcfunctions

# setup the environment for the snmpd process
setupEnv $CONSOLE_PATH

#-03 start
netsnmpLogRotateFileName="/etc/logrotate.d/net-snmp";
if [ -e "${netsnmpLogRotateFileName}" ]; then
   echo "Removing the NetSNMP log rotate file: ${netsnmpLogRotateFileName}";
   rm -fv "${netsnmpLogRotateFileName}"
fi
#-03 end

# start the snmp daemon with the given .conf file and the snmp agent parms
if /usr/sbin/snmpd -c $CONFFILE -P $PIDFILE $PARMS -l /dev/null -s udp:161 tcp:161 udp6:161 tcp6:161; then
    exit 0
else
    exit 1
fi
