PageRenderTime 79ms CodeModel.GetById 72ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/rc2.d/S20snmpd

http://github.com/brinkman83/bashrc
Shell | 98 lines | 70 code | 9 blank | 19 comment | 13 complexity | 95c97fe21410416ffc5a680bdf54a63a MD5 | raw file
 1#! /bin/sh -e
 2### BEGIN INIT INFO
 3# Provides:           snmpd snmptrapd
 4# Required-Start:     $network $remote_fs $syslog
 5# Required-Stop:      $network $remote_fs $syslog
 6# Default-Start:      2 3 4 5
 7# Default-Stop:       0 1 6
 8# Short-Description:  SNMP agents
 9# Description:        NET SNMP (Simple Network Management Protocol) Agents
10### END INIT INFO
11#
12# Author:    Jochen Friedrich <jochen@scram.de>
13#
14set -e
15
16. /lib/lsb/init-functions
17
18export PATH=/sbin:/usr/sbin:/bin:/usr/bin
19
20test -x /usr/sbin/snmpd || exit 0
21test -x /usr/sbin/snmptrapd || exit 0
22
23# Defaults
24export MIBDIRS=/usr/share/snmp/mibs
25SNMPDRUN=yes
26SNMPDOPTS='-Lsd -Lf /dev/null -p /var/run/snmpd.pid'
27TRAPDRUN=no
28TRAPDOPTS='-Lsd -p /var/run/snmptrapd.pid'
29
30# Reads config file (will override defaults above)
31[ -r /etc/default/snmpd ] && . /etc/default/snmpd
32
33# Cd to / before starting any daemons.
34cd /
35
36# Create compatibility link to old AgentX socket location
37if [ "$SNMPDCOMPAT" = "yes" ] && [ "$1" != status ]; then
38  ln -sf /var/agentx/master /var/run/agentx
39fi
40
41case "$1" in
42  start)
43    log_daemon_msg "Starting network management services:"
44    if [ "$SNMPDRUN" = "yes" -a -f /etc/snmp/snmpd.conf ]; then
45	start-stop-daemon --quiet --start --oknodo --exec /usr/sbin/snmpd \
46	    -- $SNMPDOPTS
47	log_progress_msg " snmpd"
48    fi
49    if [ "$TRAPDRUN" = "yes" -a -f /etc/snmp/snmptrapd.conf ]; then
50	start-stop-daemon --quiet --start --oknodo --exec /usr/sbin/snmptrapd \
51	    -- $TRAPDOPTS
52	log_progress_msg " snmptrapd"
53    fi
54    ;;
55  stop)
56    log_daemon_msg "Stopping network management services:"
57    start-stop-daemon --quiet --stop --oknodo --exec /usr/sbin/snmpd
58    log_progress_msg " snmpd"
59    start-stop-daemon --quiet --stop --oknodo --exec /usr/sbin/snmptrapd
60    log_progress_msg " snmptrapd"
61    ;;
62  restart)
63    log_daemon_msg "Restarting network management services:"
64    start-stop-daemon --quiet --stop --oknodo --exec /usr/sbin/snmpd
65    start-stop-daemon --quiet --stop --oknodo --exec /usr/sbin/snmptrapd
66    # Allow the daemons time to exit completely.
67    sleep 2
68    if [ "$SNMPDRUN" = "yes" -a -f /etc/snmp/snmpd.conf ]; then
69	start-stop-daemon --quiet --start --exec /usr/sbin/snmpd -- $SNMPDOPTS
70	log_progress_msg " snmpd"
71    fi
72    if [ "$TRAPDRUN" = "yes" -a -f /etc/snmp/snmptrapd.conf ]; then
73	# Allow snmpd time to start up.
74	sleep 1
75	start-stop-daemon --quiet --start --exec /usr/sbin/snmptrapd -- $TRAPDOPTS
76	log_progress_msg " snmptrapd"
77    fi
78    ;;
79  reload|force-reload)
80    log_daemon_msg "Reloading network management services:"
81    if [ "$SNMPDRUN" = "yes" -a -f /etc/snmp/snmpd.conf ]; then
82        start-stop-daemon --quiet --stop --signal 1 \
83	    --pidfile /var/run/snmpd.pid --exec /usr/sbin/snmpd
84	log_progress_msg " snmpd"
85    fi
86    ;;
87  status)
88    status=0
89    status_of_proc /usr/sbin/snmpd snmpd || status=$?
90    status_of_proc /usr/sbin/snmptrapd snmptrapd || status=$?
91    exit $status
92    ;;
93  *)
94    echo "Usage: /etc/init.d/snmpd {start|stop|restart|reload|force-reload|status}"
95    exit 1
96esac
97
98exit 0