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.
67 lines
1.4 KiB
67 lines
1.4 KiB
#!/bin/sh
|
|
|
|
DAEMON=/usr/bin/tera-snmpd
|
|
PIDFILE=/run/tera-snmpd.pid
|
|
ENVFILE=/etc/tera/tera-snmpd.env
|
|
RUN_AS=root:tera
|
|
|
|
ensure_group() {
|
|
if ! grep -q '^tera:' /etc/group; then
|
|
addgroup -S tera || return 1
|
|
fi
|
|
}
|
|
|
|
prepare_runtime() {
|
|
ensure_group || return 1
|
|
mkdir -p /run/tera-snmpd /etc/snmp /var/lib/net-snmp || return 1
|
|
chown root:tera /run/tera-snmpd || return 1
|
|
chown root:root /etc/snmp /var/lib/net-snmp || return 1
|
|
chmod 0750 /run/tera-snmpd /etc/snmp || return 1
|
|
chmod 0700 /var/lib/net-snmp || return 1
|
|
}
|
|
|
|
load_environment() {
|
|
if [ -r "$ENVFILE" ]; then
|
|
set -a
|
|
. "$ENVFILE"
|
|
set +a
|
|
fi
|
|
}
|
|
|
|
is_running() {
|
|
[ -r "$PIDFILE" ] || return 1
|
|
pid="$(cat "$PIDFILE" 2>/dev/null)"
|
|
[ -n "$pid" ] && kill -0 "$pid" 2>/dev/null
|
|
}
|
|
|
|
start_service() {
|
|
if is_running; then
|
|
echo "tera-snmpd is already running"
|
|
return 0
|
|
fi
|
|
rm -f "$PIDFILE"
|
|
[ -x "$DAEMON" ] || { echo "missing $DAEMON" >&2; return 1; }
|
|
[ -x /etc/init.d/S59snmpd ] || { echo "missing Net-SNMP service" >&2; return 1; }
|
|
prepare_runtime || return 1
|
|
load_environment
|
|
umask 0007
|
|
start-stop-daemon -S -q -b -m -p "$PIDFILE" -c "$RUN_AS" -x "$DAEMON"
|
|
}
|
|
|
|
stop_service() {
|
|
if ! is_running; then
|
|
rm -f "$PIDFILE"
|
|
return 0
|
|
fi
|
|
start-stop-daemon -K -q -p "$PIDFILE" -x "$DAEMON"
|
|
rm -f "$PIDFILE"
|
|
}
|
|
|
|
case "$1" in
|
|
start) start_service ;;
|
|
stop) stop_service ;;
|
|
restart) stop_service && start_service ;;
|
|
status) is_running ;;
|
|
*) echo "Usage: $0 {start|stop|restart|status}" >&2; exit 1 ;;
|
|
esac
|
|
|
|
|