Merge pull request #8198 from jefferyto/mini-snmpd-init
mini_snmpd: Update init script
This commit is contained in:
commit
3d2b0e976c
2 changed files with 61 additions and 54 deletions
|
@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk
|
|||
|
||||
PKG_NAME:=mini_snmpd
|
||||
PKG_VERSION:=1.4-rc1
|
||||
PKG_RELEASE:=3
|
||||
PKG_RELEASE:=4
|
||||
PKG_MAINTAINER:=Marcin Jurkowski <marcin1j@gmail.com>
|
||||
PKG_LICENSE:=GPL-2.0
|
||||
PKG_LICENSE_FILES:=COPYING
|
||||
|
|
|
@ -8,6 +8,10 @@ USE_PROCD=1
|
|||
PROG=/usr/bin/mini_snmpd
|
||||
NAME=mini_snmpd
|
||||
|
||||
global_respawn_threshold=
|
||||
global_respawn_timeout=
|
||||
global_respawn_retry=
|
||||
|
||||
_log() {
|
||||
logger -p daemon.info -t mini_snmpd "$@"
|
||||
}
|
||||
|
@ -49,14 +53,14 @@ mini_snmpd_validation="enabled:bool:0 \
|
|||
append_disk() {
|
||||
local disk="$1" disk_count
|
||||
[ -z $disk_count ] && disk_count=0
|
||||
if grep -qF "$disk" /proc/mounts ; then
|
||||
if grep -qF "$disk" /proc/mounts; then
|
||||
# check the fileystem is mountpoint, and directory search permissions available for statfs()
|
||||
# presence as a directory -d test done is already done by uci_validate_section()
|
||||
[ -x "$disk" ] || {
|
||||
_err "$cfg: mountpoint $disk for snmp monitoring EACCES error. Check permissions, ignoring"
|
||||
return 1
|
||||
}
|
||||
if [ $disk_count -lt 4 ] ; then
|
||||
if [ $disk_count -lt 4 ]; then
|
||||
append disks_arg "$disk" ','
|
||||
disk_count=$((disk_count++))
|
||||
else
|
||||
|
@ -102,16 +106,15 @@ watch_interfaces() {
|
|||
config_get listen_interface "$cfg" listen_interface
|
||||
# If the interface is up & instance is running we'll watch at the instance level and only restart that instance if it's bound interface changes
|
||||
# Regardless of ubus knowing about an interface (in the case it's not yet configured)
|
||||
[ -n "$listen_interface" ] && trigger_interfaces="${listen_interface} ${trigger_interfaces} "
|
||||
[ -n "$listen_interface" ] && trigger_interfaces="$listen_interface $trigger_interfaces"
|
||||
# Restart daemon if one of monitored interfaces changes
|
||||
config_get reload_interfaces "$cfg" interfaces
|
||||
|
||||
}
|
||||
|
||||
validate_mini_snmpd_section() {
|
||||
# validate a mini_snmpd instance in uci config file mini_snmpd
|
||||
# http://luci.subsignal.org/trac/wiki/Documentation/Datatypes ubox/validate/validate.c
|
||||
uci_validate_section mini_snmpd mini_snmpd "${1}" $mini_snmpd_validation
|
||||
uci_load_validate mini_snmpd mini_snmpd "$1" "$2" $mini_snmpd_validation
|
||||
}
|
||||
|
||||
|
||||
|
@ -123,8 +126,8 @@ service_triggers() {
|
|||
# this only watches interfaces for which there is no running instance due to interface down / not in ubus
|
||||
# hence start not reload, this trigger will not affect running instances as another start will not change their procd command arguments
|
||||
# or stop the already running process
|
||||
[ -n "$trigger_interfaces" ] & {
|
||||
for n in $trigger_interfaces ; do
|
||||
[ -n "$trigger_interfaces" ] && {
|
||||
for n in $trigger_interfaces; do
|
||||
procd_add_interface_trigger "interface.*" $n /etc/init.d/mini_snmpd start
|
||||
done
|
||||
}
|
||||
|
@ -141,13 +144,7 @@ service_triggers() {
|
|||
start_instance() {
|
||||
local cfg validation_failed validation_err disks_arg interfaces_arg
|
||||
cfg="$1"
|
||||
#uci_validate_section should unset undefined variables from other instances
|
||||
#however defining uci variables as local will scope them to this instance
|
||||
#"local variables are also visible to functions called by the parent function" so it's good practice
|
||||
local enabled ipv6 debug auth community contact location listen_interface \
|
||||
udp_port tcp_port vendor_oid mib_timeout
|
||||
local disks="" interfaces=""
|
||||
validate_mini_snmpd_section "$cfg" 2>/dev/null || validation_failed=1
|
||||
[ "$2" = 0 ] || validation_failed=1
|
||||
[ "$enabled" == 1 ] || {
|
||||
_log "instance:$cfg disabled not starting"
|
||||
return 1
|
||||
|
@ -172,7 +169,7 @@ start_instance() {
|
|||
_err "validation of $NAME configuration for $cfg instance failed, all tests should be within constraints"
|
||||
_err "please edit the configuration values below using [l]uci "
|
||||
validation_err=`/sbin/validate_data mini_snmpd mini_snmpd "$cfg" $mini_snmpd_validation 2>&1 | sed '/with\ false$/!d;s/validates\ as\ /needs\ to\ be\ /;s/with\ false//' `
|
||||
_err "${validation_err}"
|
||||
_err "$validation_err"
|
||||
return 1
|
||||
}
|
||||
config_list_foreach "$cfg" 'disks' append_disk
|
||||
|
@ -183,13 +180,24 @@ start_instance() {
|
|||
return 1
|
||||
}
|
||||
|
||||
[ -z "$respawn_threshold$respawn_timeout$respawn_retry" ] && {
|
||||
respawn_threshold=$global_respawn_threshold
|
||||
respawn_timeout=$global_respawn_timeout
|
||||
respawn_retry=$global_respawn_retry
|
||||
}
|
||||
[ -z "$global_respawn_threshold$global_respawn_timeout$global_respawn_retry" ] && {
|
||||
global_respawn_threshold=$respawn_threshold
|
||||
global_respawn_timeout=$respawn_timeout
|
||||
global_respawn_retry=$respawn_retry
|
||||
}
|
||||
|
||||
procd_open_instance
|
||||
|
||||
procd_set_param command "$PROG" -n
|
||||
procd_set_param stdout "1"
|
||||
procd_set_param stderr "1"
|
||||
# don't the like default respawn values? you can override through uci.
|
||||
# vars left as global so you only need to do it in the first mini_snmpd instance
|
||||
# vars saved as global so you only need to do it in the first mini_snmpd instance
|
||||
procd_set_param respawn ${respawn_threshold:-3600} ${respawn_timeout:-10} ${respawn_retry:-1}
|
||||
# this monitors ubus changes
|
||||
[ -n "$listen_interface" ] && {
|
||||
|
@ -202,11 +210,11 @@ start_instance() {
|
|||
# igmpproxy has this as well as "procd_set_param netdev"
|
||||
|
||||
append_arg "-c" "$community"
|
||||
append_arg "-L" "${location}"
|
||||
append_arg "-C" "${contact}"
|
||||
append_arg "-L" "$location"
|
||||
append_arg "-C" "$contact"
|
||||
append_arg "-p" $udp_port
|
||||
append_arg "-P" $tcp_port
|
||||
append_arg "-V" "${vendor_oid}"
|
||||
append_arg "-V" "$vendor_oid"
|
||||
append_arg "-t" $mib_timeout
|
||||
|
||||
[ "$ipv6" = 1 ] && procd_append_param command "-6"
|
||||
|
@ -232,6 +240,5 @@ start_service() {
|
|||
. /lib/functions/network.sh
|
||||
|
||||
config_load 'mini_snmpd'
|
||||
config_foreach start_instance 'mini_snmpd'
|
||||
config_foreach validate_mini_snmpd_section 'mini_snmpd' start_instance
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue