snmpd 1.44 KB
Newer Older
1 2
#!/bin/sh

3
SNMP_PID=/var/run/snmpd.pid
4
SNMP_CONF=/etc/snmpd.conf
5
dotconfig=/wr/etc/dot-config
6

7 8 9 10 11 12 13 14 15 16 17 18
start_counter() {
	# increase boot counter
	COUNTER_FILE="/tmp/start_cnt_snmpd"
	START_COUNTER=1
	if [ -f "$COUNTER_FILE" ];
	then
	    read -r START_COUNTER < $COUNTER_FILE
	    START_COUNTER=$((START_COUNTER+1))
	fi
	echo "$START_COUNTER" > $COUNTER_FILE
}

19
start() {
20
    echo -n "Starting snmpd daemon: "
21 22 23 24 25 26 27 28 29 30 31 32 33

    if [ -f "$dotconfig" ]; then
	. "$dotconfig"
    else
	echo "$0 unable to source dot-config ($dotconfig)!"
    fi

    WRS_LOG=$CONFIG_WRS_LOG_SNMPD

    if [ -z "$WRS_LOG" ]; then
	LOG="";
    elif echo "$WRS_LOG" | grep / > /dev/null; then
        # if a pathname, use it
34
	LOG="-LF 5 $WRS_LOG";
35 36 37 38 39 40
    else
	# not a pathname: use verbatim
	LOG="-L$WRS_LOG"
    fi

    # Log source address (-a)
41
    start-stop-daemon -q -p $SNMP_PID -S \
42 43
		--exec /usr/sbin/snmpd -- $LOG -p $SNMP_PID -a -c $SNMP_CONF

44 45 46 47 48 49 50 51 52
    ret=$?
    if [ $ret -eq 0 ]; then
	start_counter
	echo "OK"
    elif [ $ret -eq 1 ]; then
	echo "Failed (already running?)"
    else
	echo "Failed"
    fi
53 54 55
}

stop() {
56 57 58
    echo -n "Stopping snmpd: "
    start-stop-daemon -K -q -p $SNMP_PID
    if [ $? -eq 0 ]; then
59
	echo "OK"
60 61
    else
	echo "Failed"
62 63
    fi
}
64

65 66
restart() {
    stop
67 68
    # give time to snmpd to stop
    sleep 1
69 70 71 72
    start
}

case "$1" in
73 74
    start)
	start
75
	;;
76 77
    stop)
	stop
78
	;;
79 80
    restart|reload)
	restart
81
	;;
82 83 84
    "")
	start
	;;
85
    *)
86 87 88 89
	echo $"Usage: $0 {start|stop|restart}"
	exit 1
	;;
esac