net-snmp/rc.snmpd
Dominique Leuenberger dd6a8df967 Accepting request 386493 from net-snmp:factory
removing md5 and des disablement
(changes entry exited already bsc#944302) (forwarded request 386328 from abergmann)

OBS-URL: https://build.opensuse.org/request/show/386493
OBS-URL: https://build.opensuse.org/package/show/openSUSE:Factory/net-snmp?expand=0&rev=79
2016-04-12 17:00:22 +00:00

195 lines
5.7 KiB
Bash

#! /bin/sh
# Copyright (c) 1996-2011 SuSE GmbH Nuernberg, Germany. All rights reserved.
#
# Author: Christopher Mahmood, Remo Behn
#
# /etc/init.d/snmpd
#
### BEGIN INIT INFO
# Provides: net-snmp snmp snmpd
# Required-Start: $remote_fs
# Should-Start: $syslog $network
# Required-Stop: $remote_fs
# Should-Stop: $syslog $network
# Default-Start: 2 3 5
# Default-Stop: 0 1 6
# Description: Net-SNMP agent
# Short-Description: Net-SNMP agent
### END INIT INFO
SNMPD=/usr/sbin/snmpd
AGENTDIR=/usr/lib/net-snmp/agents
SNMPDCONF=/etc/snmp/snmpd.conf
SNMPD_PID=/var/run/snmpd.pid
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";
if [ "$1" = "stop" ]; then exit 0;
else exit 6; fi; }
# Read config
. $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
#
# 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
}
case "$1" in
start)
echo -n "Starting snmpd"
#
# log destination "F" for file.
# do not even try to start if the log file is (2GB-1MB) big.
# the snmpd doesnt handle LFS properly
#
if [ ${SNMPD_LOGDEST:-F} = "F" ]; then
SNMPD_LOGTARGET="${SNMPD_LOGTARGET:-/var/log/net-snmpd.log}"
if [ -e "$SNMPD_LOGTARGET" ] ; then
SNMPD_SIZE_LOGFILE="$(stat -c "%s" $SNMPD_LOGTARGET)"
SNMPD_SIZE_MAX="1073741824"
if [ $SNMPD_SIZE_LOGFILE -gt $SNMPD_SIZE_MAX ] ; then
echo -e "\n\"$SNMPD_LOGTARGET\" is too large. Running 'logrotate' for net-snmp." >&2
/usr/sbin/logrotate /etc/logrotate.d/net-snmp
fi
fi
fi
#
# log destination "S" for syslog.
# define syslog facility to 'd' for LOG_DAEMON.
#
if [ ${SNMPD_LOGDEST:-F} = "S" ]; then
SNMPD_LOGTARGET="d"
fi
get_agents
# Don't add -c /etc/snmp/snmpd.conf, as it is loaded by default.
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
# /var/run can now be mounted as tmpfs
if [ ! -d /var/run/agentx ]; then
mkdir -m 0700 /var/run/agentx
fi
startproc $SNMPD $SNMPDCONF -r -A -L${SNMPD_LOGDEST:-F} ${SNMPD_LOGLEVEL:-n} $SNMPD_LOGTARGET -p $SNMPD_PID $agentargs $SNMPDNOSMUX $SNMPDNOTCPWRAPPERLOG $SNMPD_LISTEN
rc_status -v
rc_reset
# start all agents
if test -n "$agents"; then
usleep 300000
for agent in $agents; do
echo -en "\tStarting `basename $agent`"
startproc -t1 $agent
rc_status -v ; rc_reset
done
fi
;;
stop)
echo -n "Shutting down snmpd:"
killproc -TERM $SNMPD
rc_status -v ; rc_reset
# we also need to make sure all agents die
get_agents
if test -n "$agents"; then
for agent in $AGENTDIR/*; do
test -x $agent || continue
echo -ne "\tShutting down `basename $agent`:"
killproc $agent
rc_status -v ; rc_reset
done
fi
;;
try-restart)
$0 status >/dev/null && $0 restart
rc_status
;;
restart)
$0 stop
$0 start
rc_status
;;
force-reload)
echo -n "Reload service snmpd:"
killproc -HUP $SNMPD
rc_status -v
;;
reload)
echo -n "Reload service snmpd:"
killproc -HUP $SNMPD
rc_status -v
;;
status)
echo -n "Checking for service snmpd:"
checkproc $SNMPD
rc_status -v
get_agents
if test -n "$agents"; then
echo -e "Checking for agents:"
for agent in $agents; do
echo -en "\t`basename $agent`"
checkproc $agent
rc_status -v
done
fi
;;
*)
echo "Usage: $0 {start|stop|try-restart|restart|force-reload|reload|status}"
exit 1
;;
esac
rc_exit