2007-01-16 00:26:37 +01:00
|
|
|
#! /bin/sh
|
2011-09-14 15:00:35 +02:00
|
|
|
# Copyright (c) 1996-2011 SuSE GmbH Nuernberg, Germany. All rights reserved.
|
2007-01-16 00:26:37 +01:00
|
|
|
#
|
2011-09-14 15:00:35 +02:00
|
|
|
# Author: Christopher Mahmood, Remo Behn
|
2007-01-16 00:26:37 +01:00
|
|
|
#
|
|
|
|
# /etc/init.d/snmpd
|
|
|
|
#
|
|
|
|
### BEGIN INIT INFO
|
|
|
|
# Provides: net-snmp snmp
|
2008-09-08 16:23:32 +02:00
|
|
|
# Required-Start: $remote_fs
|
|
|
|
# Should-Start: $syslog $network
|
|
|
|
# Required-Stop: $remote_fs
|
|
|
|
# Should-Stop: $syslog $network
|
2007-01-16 00:26:37 +01:00
|
|
|
# Default-Start: 2 3 5
|
|
|
|
# Default-Stop: 0 1 6
|
2011-09-14 15:00:35 +02:00
|
|
|
# Description: Net-SNMP agent
|
|
|
|
# Short-Description: Net-SNMP agent
|
2007-01-16 00:26:37 +01:00
|
|
|
### END INIT INFO
|
|
|
|
|
|
|
|
SNMPD=/usr/sbin/snmpd
|
|
|
|
AGENTDIR=/usr/lib/net-snmp/agents
|
|
|
|
SNMPDCONF=/etc/snmp/snmpd.conf
|
2011-09-14 15:00:35 +02:00
|
|
|
SNMPD_PID=/var/run/snmpd.pid
|
2007-01-16 00:26:37 +01:00
|
|
|
|
|
|
|
test -x $SNMPD || exit 5
|
|
|
|
|
|
|
|
# Check for existence of needed config file and read it
|
|
|
|
SNMPD_CONFIG=/etc/sysconfig/net-snmp
|
|
|
|
test -r $SNMPD_CONFIG || { echo "$SNMPD_CONFIG not existing";
|
2009-01-22 18:18:30 +01:00
|
|
|
if [ "$1" = "stop" ]; then exit 0;
|
|
|
|
else exit 6; fi; }
|
2007-01-16 00:26:37 +01:00
|
|
|
|
2009-01-22 18:18:30 +01:00
|
|
|
# Read config
|
2007-01-16 00:26:37 +01:00
|
|
|
. $SNMPD_CONFIG
|
|
|
|
|
|
|
|
# Shell functions sourced from /etc/rc.status:
|
|
|
|
# rc_check check and set local and overall rc status
|
|
|
|
# rc_status check and set local and overall rc status
|
|
|
|
# rc_status -v ditto but be verbose in local rc status
|
|
|
|
# rc_status -v -r ditto and clear the local rc status
|
|
|
|
# rc_failed set local and overall rc status to failed
|
|
|
|
# rc_failed <num> set local and overall rc status to <num><num>
|
|
|
|
# rc_reset clear local rc status (overall remains)
|
|
|
|
# rc_exit exit appropriate to overall rc status
|
|
|
|
. /etc/rc.status
|
|
|
|
|
|
|
|
# First reset status of this service
|
|
|
|
rc_reset
|
|
|
|
|
|
|
|
# Return values acc. to LSB for all commands but status:
|
|
|
|
# 0 - success
|
|
|
|
# 1 - generic or unspecified error
|
|
|
|
# 2 - invalid or excess argument(s)
|
|
|
|
# 3 - unimplemented feature (e.g. "reload")
|
|
|
|
# 4 - insufficient privilege
|
|
|
|
# 5 - program is not installed
|
|
|
|
# 6 - program is not configured
|
|
|
|
# 7 - program is not running
|
2009-01-22 18:18:30 +01:00
|
|
|
#
|
2007-01-16 00:26:37 +01:00
|
|
|
# Note that starting an already running service, stopping
|
|
|
|
# or restarting a not-running service as well as the restart
|
|
|
|
# with force-reload (in case signalling is not supported) are
|
|
|
|
# considered a success.
|
|
|
|
|
|
|
|
# check whether to enable agentx support and get list of installed
|
|
|
|
# agents
|
|
|
|
get_agents()
|
|
|
|
{
|
|
|
|
agents=
|
|
|
|
agentargs=''
|
|
|
|
for agent in $AGENTDIR/*; do
|
|
|
|
test -x $agent || continue
|
|
|
|
agents="$agents $agent"
|
|
|
|
agentargs="-x /var/run/agentx/master"
|
|
|
|
done
|
2009-01-22 18:18:30 +01:00
|
|
|
}
|
2007-01-16 00:26:37 +01:00
|
|
|
|
|
|
|
case "$1" in
|
|
|
|
start)
|
2009-01-22 18:18:30 +01:00
|
|
|
echo -n "Starting snmpd"
|
2007-01-16 00:26:37 +01:00
|
|
|
#
|
|
|
|
# do not even try to start if the log file is (2GB-1MB) big.
|
|
|
|
# the snmpd doesnt handle LFS properly
|
|
|
|
#
|
2008-10-24 22:48:33 +02:00
|
|
|
SNMPD_LOGFILE="${SNMPD_LOGFILE:-/var/log/net-snmpd.log}"
|
2007-01-16 00:26:37 +01:00
|
|
|
if [ -e "$SNMPD_LOGFILE" ] ; then
|
|
|
|
SNMPD_SIZE_LOGFILE="$(stat -c "%s" $SNMPD_LOGFILE)"
|
|
|
|
SNMPD_SIZE_MAX="1073741824"
|
|
|
|
if [ $SNMPD_SIZE_LOGFILE -gt $SNMPD_SIZE_MAX ] ; then
|
2011-09-14 15:00:35 +02:00
|
|
|
echo -e "\n\"$SNMPD_LOGFILE\" is too large. Running 'logrotate' for net-snmp." >&2
|
2007-01-16 00:26:37 +01:00
|
|
|
/usr/sbin/logrotate /etc/logrotate.d/net-snmp
|
2011-09-14 15:00:35 +02:00
|
|
|
fi
|
|
|
|
fi
|
2009-01-22 18:18:30 +01:00
|
|
|
get_agents
|
2011-09-14 15:00:35 +02:00
|
|
|
# Don't add -c /etc/snmp/snmpd.conf, as it is loaded by default.
|
2009-01-22 18:18:30 +01:00
|
|
|
if [ $SNMPDCONF = "/etc/snmp/snmpd.conf" ]; then
|
|
|
|
SNMPDCONF=""
|
|
|
|
else
|
|
|
|
SNMPDCONF="-c $SNMPDCONF"
|
|
|
|
fi
|
|
|
|
case "${SNMPD_USE_SMUX:-yes}" in
|
|
|
|
[Nn][Oo])
|
|
|
|
SNMPDNOSMUX="-I -smux"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
case "${SNMPD_LOG_SUCCESSFUL_CONNECTIONS:-yes}" in
|
|
|
|
[Nn][Oo])
|
|
|
|
SNMPDNOTCPWRAPPERLOG="--dontLogTCPWrappersConnects"
|
|
|
|
;;
|
|
|
|
esac
|
2010-05-18 20:40:49 +02:00
|
|
|
# /var/run can now be mounted as tmpfs
|
|
|
|
if [ ! -d /var/run/agentx ]; then
|
|
|
|
mkdir -m 0700 /var/run/agentx
|
|
|
|
fi
|
2011-09-14 15:00:35 +02:00
|
|
|
startproc $SNMPD $SNMPDCONF -r -A -LF ${SNMPD_LOGLEVEL:-n} $SNMPD_LOGFILE -p $SNMPD_PID $agentargs $SNMPDNOSMUX $SNMPDNOTCPWRAPPERLOG
|
2009-01-22 18:18:30 +01:00
|
|
|
rc_status -v
|
|
|
|
rc_reset
|
2007-01-16 00:26:37 +01:00
|
|
|
|
2009-01-22 18:18:30 +01:00
|
|
|
# start all agents
|
|
|
|
if test -n "$agents"; then
|
|
|
|
usleep 300000
|
|
|
|
for agent in $agents; do
|
2007-01-16 00:26:37 +01:00
|
|
|
echo -en "\tStarting `basename $agent`"
|
2009-01-22 18:18:30 +01:00
|
|
|
startproc -t1 $agent
|
|
|
|
rc_status -v ; rc_reset
|
2007-01-16 00:26:37 +01:00
|
|
|
done
|
2009-01-22 18:18:30 +01:00
|
|
|
fi
|
|
|
|
;;
|
2007-01-16 00:26:37 +01:00
|
|
|
stop)
|
2009-01-22 18:18:30 +01:00
|
|
|
echo -n "Shutting down snmpd:"
|
|
|
|
killproc -TERM $SNMPD
|
|
|
|
rc_status -v ; rc_reset
|
|
|
|
# we also need to make sure all agents die
|
|
|
|
if test -n "$agents"; then
|
2007-01-16 00:26:37 +01:00
|
|
|
for agent in $AGENTDIR/*; do
|
|
|
|
test -x $agent || continue
|
2009-01-22 18:18:30 +01:00
|
|
|
echo -ne "\tShutting down `basename $agent`:"
|
2007-01-16 00:26:37 +01:00
|
|
|
killproc $agent
|
2009-01-22 18:18:30 +01:00
|
|
|
rc_status -v ; rc_reset
|
2007-01-16 00:26:37 +01:00
|
|
|
done
|
2009-01-22 18:18:30 +01:00
|
|
|
fi
|
|
|
|
;;
|
2007-01-16 00:26:37 +01:00
|
|
|
try-restart)
|
2009-01-22 18:18:30 +01:00
|
|
|
$0 status >/dev/null && $0 restart
|
|
|
|
rc_status
|
|
|
|
;;
|
2007-01-16 00:26:37 +01:00
|
|
|
restart)
|
2009-01-22 18:18:30 +01:00
|
|
|
$0 stop
|
|
|
|
$0 start
|
|
|
|
rc_status
|
|
|
|
;;
|
2007-01-16 00:26:37 +01:00
|
|
|
force-reload)
|
2009-01-22 18:18:30 +01:00
|
|
|
echo -n "Reload service snmpd:"
|
|
|
|
killproc -HUP $SNMPD
|
|
|
|
rc_status -v
|
|
|
|
;;
|
2007-01-16 00:26:37 +01:00
|
|
|
reload)
|
2009-01-22 18:18:30 +01:00
|
|
|
echo -n "Reload service snmpd:"
|
|
|
|
killproc -HUP $SNMPD
|
|
|
|
rc_status -v
|
|
|
|
;;
|
2007-01-16 00:26:37 +01:00
|
|
|
status)
|
2009-01-22 18:18:30 +01:00
|
|
|
echo -n "Checking for service snmpd:"
|
|
|
|
checkproc $SNMPD
|
|
|
|
rc_status -v
|
|
|
|
get_agents
|
|
|
|
if test -n "$agents"; then
|
|
|
|
echo -e "Checking for agents:"
|
2007-01-16 00:26:37 +01:00
|
|
|
|
2009-01-22 18:18:30 +01:00
|
|
|
for agent in $agents; do
|
2007-01-16 00:26:37 +01:00
|
|
|
echo -en "\t`basename $agent`"
|
|
|
|
checkproc $agent
|
|
|
|
rc_status -v
|
|
|
|
done
|
2009-01-22 18:18:30 +01:00
|
|
|
fi
|
|
|
|
;;
|
2007-01-16 00:26:37 +01:00
|
|
|
*)
|
2009-01-22 18:18:30 +01:00
|
|
|
echo "Usage: $0 {start|stop|try-restart|restart|force-reload|reload|status}"
|
|
|
|
exit 1
|
|
|
|
;;
|
2007-01-16 00:26:37 +01:00
|
|
|
esac
|
|
|
|
rc_exit
|
|
|
|
|