Patrick Williams | b48b7b4 | 2016-08-17 15:04:38 -0500 | [diff] [blame] | 1 | #! /bin/sh |
| 2 | # /etc/init.d/snmpd: start snmp daemon. |
| 3 | |
| 4 | . /etc/init.d/functions |
| 5 | |
Patrick Williams | b48b7b4 | 2016-08-17 15:04:38 -0500 | [diff] [blame] | 6 | # Defaults |
| 7 | export MIBDIRS=/usr/share/snmp/mibs |
| 8 | SNMPDRUN=yes |
| 9 | SNMPDOPTS='-Lsd -Lf /dev/null -p /var/run/snmpd.pid' |
| 10 | TRAPDRUN=no |
| 11 | TRAPDOPTS='-Lsd -p /var/run/snmptrapd.pid' |
| 12 | PIDFILE=/var/run/snmpd.pid |
| 13 | SPIDFILE=/var/run/snmptrapd.pid |
| 14 | |
| 15 | # Reads config file if exists (will override defaults above) |
| 16 | [ -r /etc/default/snmpd ] && . /etc/default/snmpd |
| 17 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 18 | [ "$SNMPDRUN" = "yes" ] && { test -x /usr/sbin/snmpd || exit 0; } |
| 19 | [ "$TRAPDRUN" = "yes" ] && { test -x /usr/sbin/snmptrapd || exit 0; } |
| 20 | |
Patrick Williams | b48b7b4 | 2016-08-17 15:04:38 -0500 | [diff] [blame] | 21 | case "$1" in |
| 22 | start) |
| 23 | echo -n "Starting network management services:" |
| 24 | if [ "$SNMPDRUN" = "yes" -a -f /etc/snmp/snmpd.conf -a ! -f "$PIDFILE" ]; then |
| 25 | start-stop-daemon -o --start --quiet --name snmpd --pidfile "$PIDFILE" \ |
| 26 | --exec /usr/sbin/snmpd -- $SNMPDOPTS |
| 27 | echo -n " snmpd" |
| 28 | fi |
| 29 | if [ "$TRAPDRUN" = "yes" -a -f /etc/snmp/snmptrapd.conf -a ! -f "$SPIDFILE" ]; then |
| 30 | start-stop-daemon -o --start --quiet --name snmptrapd --pidfile "$SPIDFILE" \ |
| 31 | --exec /usr/sbin/snmptrapd -- $TRAPDOPTS |
| 32 | echo -n " snmptrapd" |
| 33 | fi |
| 34 | echo "." |
| 35 | |
| 36 | test ! -x /sbin/restorecon || /sbin/restorecon -FR /var/lib/net-snmp |
| 37 | ;; |
| 38 | stop) |
| 39 | echo -n "Stopping network management services:" |
| 40 | if [ -f "$PIDFILE" ] ; then |
| 41 | start-stop-daemon -o --stop --quiet --pidfile $PIDFILE --name snmpd |
| 42 | fi |
| 43 | echo -n " snmpd" |
| 44 | if [ -f "$SPIDFILE" ] ; then |
| 45 | start-stop-daemon -o --stop --quiet --pidfile $SPIDFILE --name snmptrapd |
| 46 | rm -rf $SPIDFILE |
| 47 | fi |
| 48 | echo -n " snmptrapd" |
| 49 | echo "." |
| 50 | ;; |
| 51 | status) |
| 52 | status /usr/sbin/snmpd; |
| 53 | exit $? |
| 54 | ;; |
| 55 | restart|reload|force-reload) |
| 56 | $0 stop |
| 57 | # Allow the daemons time to exit completely. |
| 58 | sleep 2 |
| 59 | $0 start |
| 60 | ;; |
| 61 | *) |
| 62 | echo "Usage: /etc/init.d/snmpd {start|stop|status|restart|reload|force-reload}" |
| 63 | exit 1 |
| 64 | esac |
| 65 | |
| 66 | exit 0 |