Backport the init script from precise for snmpd.

This can go away after everything is upgraded to precise,
but it's the cause of the constant puppet attempts to restart snmpd on our
servers.

Change-Id: I99b1931aefa3444d5ceef8b6dd6014152f3f53a0
This commit is contained in:
Monty Taylor 2012-07-22 23:27:01 -05:00
parent 4b0d9b27f6
commit 26d074aba3
2 changed files with 117 additions and 1 deletions

102
modules/snmpd/files/snmpd.init Executable file
View File

@ -0,0 +1,102 @@
#! /bin/sh -e
### BEGIN INIT INFO
# Provides: snmpd snmptrapd
# Required-Start: $network $remote_fs $syslog
# Required-Stop: $network $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: SNMP agents
# Description: NET SNMP (Simple Network Management Protocol) Agents
### END INIT INFO
#
# Author: Jochen Friedrich <jochen@scram.de>
#
set -e
. /lib/lsb/init-functions
export PATH=/sbin:/usr/sbin:/bin:/usr/bin
test -x /usr/sbin/snmpd || exit 0
test -x /usr/sbin/snmptrapd || exit 0
# Defaults
export MIBDIRS=/usr/share/mibs/site:/usr/share/snmp/mibs:/usr/share/mibs/iana:/usr/share/mibs/ietf:/usr/share/mibs/netsnmp
SNMPDRUN=yes
SNMPDOPTS='-Lsd -Lf /dev/null -p /var/run/snmpd.pid'
TRAPDRUN=no
TRAPDOPTS='-Lsd -p /var/run/snmptrapd.pid'
# Reads config file (will override defaults above)
[ -r /etc/default/snmpd ] && . /etc/default/snmpd
# Cd to / before starting any daemons.
cd /
# Create compatibility link to old AgentX socket location
if [ "$SNMPDCOMPAT" = "yes" ] && [ "$1" != status ]; then
ln -sf /var/agentx/master /var/run/agentx
fi
case "$1" in
start)
log_daemon_msg "Starting network management services:"
if [ "$SNMPDRUN" = "yes" -a -f /etc/snmp/snmpd.conf ]; then
start-stop-daemon --quiet --start --oknodo --exec /usr/sbin/snmpd \
-- $SNMPDOPTS
log_progress_msg " snmpd"
fi
if [ "$TRAPDRUN" = "yes" -a -f /etc/snmp/snmptrapd.conf ]; then
start-stop-daemon --quiet --start --oknodo --exec /usr/sbin/snmptrapd \
-- $TRAPDOPTS
log_progress_msg " snmptrapd"
fi
;;
stop)
log_daemon_msg "Stopping network management services:"
start-stop-daemon --quiet --stop --oknodo --exec /usr/sbin/snmpd
log_progress_msg " snmpd"
start-stop-daemon --quiet --stop --oknodo --exec /usr/sbin/snmptrapd
log_progress_msg " snmptrapd"
;;
restart)
log_daemon_msg "Restarting network management services:"
start-stop-daemon --quiet --stop --oknodo --exec /usr/sbin/snmpd
start-stop-daemon --quiet --stop --oknodo --exec /usr/sbin/snmptrapd
# Allow the daemons time to exit completely.
sleep 2
if [ "$SNMPDRUN" = "yes" -a -f /etc/snmp/snmpd.conf ]; then
start-stop-daemon --quiet --start --exec /usr/sbin/snmpd -- $SNMPDOPTS
log_progress_msg " snmpd"
fi
if [ "$TRAPDRUN" = "yes" -a -f /etc/snmp/snmptrapd.conf ]; then
# Allow snmpd time to start up.
sleep 1
start-stop-daemon --quiet --start --exec /usr/sbin/snmptrapd -- $TRAPDOPTS
log_progress_msg " snmptrapd"
fi
;;
reload|force-reload)
log_daemon_msg "Reloading network management services:"
if [ "$SNMPDRUN" = "yes" -a -f /etc/snmp/snmpd.conf ]; then
start-stop-daemon --quiet --stop --signal 1 \
--pidfile /var/run/snmpd.pid --exec /usr/sbin/snmpd
log_progress_msg " snmpd"
fi
;;
status)
status=0
if [ "$SNMPDRUN" = "yes" -a -f /etc/snmp/snmpd.conf ]; then
status_of_proc /usr/sbin/snmpd snmpd || status=$?
fi
if [ "$TRAPDRUN" = "yes" -a -f /etc/snmp/snmptrapd.conf ]; then
status_of_proc /usr/sbin/snmptrapd snmptrapd || status=$?
fi
exit $status
;;
*)
echo "Usage: /etc/init.d/snmpd {start|stop|restart|reload|force-reload|status}"
exit 1
esac
exit 0

View File

@ -3,7 +3,21 @@ class snmpd {
service { snmpd:
ensure => running,
hasrestart => true,
require => File["/etc/snmp/snmpd.conf"],
require => [File["/etc/snmp/snmpd.conf"],
File["/etc/init.d/snmpd"]]
}
# This file is only needed on machines pre-precise. There is a bug in
# the previous init script versions which causes them to attempt
# snmptrapd even if it's configured not to run, and then to report
# failure.
file { "/etc/init.d/snmpd":
owner => 'root',
group => 'root',
mode => 755,
ensure => 'present',
source => 'puppet:///modules/snmpd/snmpd.init',
replace => 'true',
require => Package[snmpd]
}
file { "/etc/snmp/snmpd.conf":
owner => 'root',