blob: 47995466fbdbf211d0612db005348a54ff83929f [file] [log] [blame]
Patrick Williamsb48b7b42016-08-17 15:04:38 -05001#! /bin/sh
2# /etc/init.d/snmpd: start snmp daemon.
3
4. /etc/init.d/functions
5
Patrick Williamsb48b7b42016-08-17 15:04:38 -05006# Defaults
7export MIBDIRS=/usr/share/snmp/mibs
8SNMPDRUN=yes
9SNMPDOPTS='-Lsd -Lf /dev/null -p /var/run/snmpd.pid'
10TRAPDRUN=no
11TRAPDOPTS='-Lsd -p /var/run/snmptrapd.pid'
12PIDFILE=/var/run/snmpd.pid
13SPIDFILE=/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 Bishopd7bf8c12018-02-25 22:55:05 -050018[ "$SNMPDRUN" = "yes" ] && { test -x /usr/sbin/snmpd || exit 0; }
19[ "$TRAPDRUN" = "yes" ] && { test -x /usr/sbin/snmptrapd || exit 0; }
20
Patrick Williamsb48b7b42016-08-17 15:04:38 -050021case "$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
64esac
65
66exit 0