You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

43 lines
1.4 KiB

#!/bin/sh
# The privileged adapter writes configuration only after this stop completes.
DAEMON=/usr/sbin/snmpd
CONFIG=/etc/snmp/snmpd.conf
PIDFILE=/var/run/snmpd.pid
SNMPDRUN=yes
SNMPDOPTS='-Lsd -Lf /dev/null -p /var/run/snmpd.pid'
export SNMP_PERSISTENT_DIR=/var/lib/net-snmp
[ ! -r /etc/default/snmpd ] || . /etc/default/snmpd
is_running() {
[ -r "$PIDFILE" ] || return 1
pid="$(cat "$PIDFILE")"
[ -n "$pid" ] && kill -0 "$pid" 2>/dev/null
}
start_service() {
[ "$SNMPDRUN" = yes ] && [ -r "$CONFIG" ] || return 0
grep -Eq '^[[:space:]]*agentAddress[[:space:]]+' "$CONFIG" || return 0
if is_running; then return 0; fi
mkdir -p "$SNMP_PERSISTENT_DIR" || return 1
chmod 0700 "$SNMP_PERSISTENT_DIR" || return 1
start-stop-daemon -q -S -x "$DAEMON" -- $SNMPDOPTS
}
stop_service() {
if ! is_running; then return 0; fi
stopped_pid="$pid"
start-stop-daemon -q -K -o -p "$PIDFILE" -x "$DAEMON" || return 1
attempts=0
while kill -0 "$stopped_pid" 2>/dev/null; do
attempts=$((attempts + 1))
[ "$attempts" -lt 50 ] || return 1
sleep 0.1
done
rm -f "$PIDFILE"
}
case "$1" in
start) start_service ;;
stop) stop_service ;;
restart) stop_service && start_service ;;
reload|force-reload) if is_running; then kill -HUP "$pid"; fi ;;
status) is_running ;;
*) echo "Usage: $0 {start|stop|restart|reload|force-reload|status}" >&2; exit 1 ;;
esac