From e2b43afc857f9204f1ff234500d533665b8c8d35 Mon Sep 17 00:00:00 2001 From: Stijn Tintel Date: Wed, 18 Feb 2015 04:46:05 +0100 Subject: [PATCH 1/4] net-snmp: remove /etc/default/snmpd Debianism Signed-off-by: Stijn Tintel --- net/net-snmp/Makefile | 6 ------ net/net-snmp/files/snmpd.default | 1 - net/net-snmp/files/snmpd.init | 3 +-- 3 files changed, 1 insertion(+), 9 deletions(-) delete mode 100644 net/net-snmp/files/snmpd.default diff --git a/net/net-snmp/Makefile b/net/net-snmp/Makefile index 6fbf1b8bde..5736e0d7d4 100644 --- a/net/net-snmp/Makefile +++ b/net/net-snmp/Makefile @@ -216,7 +216,6 @@ define Package/libnetsnmp/install endef define Package/snmpd/conffiles -/etc/default/snmpd /etc/config/snmpd endef @@ -225,8 +224,6 @@ define Package/snmpd/install $(INSTALL_DATA) ./files/snmpd.conf $(1)/etc/config/snmpd $(INSTALL_DIR) $(1)/etc/snmp ln -sf /var/run/snmpd.conf $(1)/etc/snmp/ - $(INSTALL_DIR) $(1)/etc/default - $(INSTALL_DATA) ./files/snmpd.default $(1)/etc/default/snmpd $(INSTALL_DIR) $(1)/etc/init.d $(INSTALL_BIN) ./files/snmpd.init $(1)/etc/init.d/snmpd $(INSTALL_DIR) $(1)/usr/sbin @@ -234,7 +231,6 @@ define Package/snmpd/install endef define Package/snmpd-static/conffiles -/etc/default/snmpd /etc/config/snmpd endef @@ -243,8 +239,6 @@ define Package/snmpd-static/install $(INSTALL_DATA) ./files/snmpd.conf $(1)/etc/config/snmpd $(INSTALL_DIR) $(1)/etc/snmp ln -sf /var/run/snmpd.conf $(1)/etc/snmp/ - $(INSTALL_DIR) $(1)/etc/default - $(INSTALL_DATA) ./files/snmpd.default $(1)/etc/default/snmpd $(INSTALL_DIR) $(1)/etc/init.d $(INSTALL_BIN) ./files/snmpd.init $(1)/etc/init.d/snmpd $(INSTALL_DIR) $(1)/usr/sbin diff --git a/net/net-snmp/files/snmpd.default b/net/net-snmp/files/snmpd.default deleted file mode 100644 index 758c8e44fe..0000000000 --- a/net/net-snmp/files/snmpd.default +++ /dev/null @@ -1 +0,0 @@ -OPTIONS="-Lf /dev/null -p /var/run/snmpd.pid" diff --git a/net/net-snmp/files/snmpd.init b/net/net-snmp/files/snmpd.init index 2668b7b3e5..bde785a5bd 100644 --- a/net/net-snmp/files/snmpd.init +++ b/net/net-snmp/files/snmpd.init @@ -2,7 +2,7 @@ # Copyright (C) 2008 OpenWrt.org START=50 -DEFAULT=/etc/default/snmpd +OPTIONS="-Lf /dev/null -p /var/run/snmpd.pid" LIB_D=/var/lib/snmp LOG_D=/var/log RUN_D=/var/run @@ -148,7 +148,6 @@ start() { config_foreach snmpd_exec_add exec config_foreach snmpd_disk_add disk - [ -f $DEFAULT ] && . $DEFAULT $DEBUG /usr/sbin/snmpd $OPTIONS } stop() { From 8faff3334f319f8a198e0da31b7f25263e407919 Mon Sep 17 00:00:00 2001 From: Stijn Tintel Date: Wed, 18 Feb 2015 05:05:27 +0100 Subject: [PATCH 2/4] net-snmp: convert snmpd to procd Signed-off-by: Stijn Tintel --- net/net-snmp/files/snmpd.init | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/net/net-snmp/files/snmpd.init b/net/net-snmp/files/snmpd.init index bde785a5bd..24488e7a52 100644 --- a/net/net-snmp/files/snmpd.init +++ b/net/net-snmp/files/snmpd.init @@ -2,12 +2,10 @@ # Copyright (C) 2008 OpenWrt.org START=50 -OPTIONS="-Lf /dev/null -p /var/run/snmpd.pid" -LIB_D=/var/lib/snmp -LOG_D=/var/log -RUN_D=/var/run -PID_F=$RUN_D/snmpd.pid -RUN_C=$RUN_D/snmpd.conf +USE_PROCD=1 +PROG="/usr/sbin/snmpd" + +RUN_C="/var/run/snmpd.conf" snmpd_agent_add() { local cfg="$1" @@ -129,11 +127,11 @@ snmpd_disk_add() { [ -n "$size" ] || return 0 echo "$disk $partition $size" >> $RUN_C } -start() { - [ -d $LIB_D ] || mkdir -p $LIB_D - [ -d $LOG_D ] || mkdir -p $LOG_D - [ -d $RUN_D ] || mkdir -p $RUN_D - [ -f $RUN_C ] && rm -f $RUN_C + +start_service() { + [ -f "$RUN_C" ] && rm -f "$RUN_C" + + procd_open_instance config_load snmpd @@ -148,9 +146,13 @@ start() { config_foreach snmpd_exec_add exec config_foreach snmpd_disk_add disk - $DEBUG /usr/sbin/snmpd $OPTIONS + procd_set_param command $PROG -Lf /dev/null -f + procd_set_param file $RUN_C + procd_set_param respawn + + procd_close_instance } -stop() { - [ -f $PID_F ] && kill $(cat $PID_F) - [ -f $RUN_C ] && rm -f $RUN_C + +stop_service() { + [ -f "$RUN_C" ] && rm -f "$RUN_C" } From 53fc8d3191cf9dc712cab9d7ae6a4b3d179fbdd1 Mon Sep 17 00:00:00 2001 From: Stijn Tintel Date: Wed, 18 Feb 2015 05:15:01 +0100 Subject: [PATCH 3/4] net-snmp: cosmetic changes in snmpd init script - Refactor RUN_C into CONFIGFILE, as used in dnsmasq and igmpproxy init scripts. - Add a newline after each function definition. Signed-off-by: Stijn Tintel --- net/net-snmp/files/snmpd.init | 47 +++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/net/net-snmp/files/snmpd.init b/net/net-snmp/files/snmpd.init index 24488e7a52..a261447668 100644 --- a/net/net-snmp/files/snmpd.init +++ b/net/net-snmp/files/snmpd.init @@ -5,30 +5,32 @@ START=50 USE_PROCD=1 PROG="/usr/sbin/snmpd" -RUN_C="/var/run/snmpd.conf" +CONFIGFILE="/var/run/snmpd.conf" snmpd_agent_add() { local cfg="$1" config_get agentaddress "$cfg" agentaddress [ -n "$agentaddress" ] || return 0 - echo "agentaddress $agentaddress" >> $RUN_C + echo "agentaddress $agentaddress" >> $CONFIGFILE } + snmpd_system_add() { local cfg="$1" config_get syslocation "$cfg" sysLocation - [ -n "$syslocation" ] && echo "sysLocation $syslocation" >> $RUN_C + [ -n "$syslocation" ] && echo "sysLocation $syslocation" >> $CONFIGFILE config_get syscontact "$cfg" sysContact - [ -n "$syscontact" ] && echo "sysContact $syscontact" >> $RUN_C + [ -n "$syscontact" ] && echo "sysContact $syscontact" >> $CONFIGFILE config_get sysname "$cfg" sysName - [ -n "$sysname" ] && echo "sysName $sysname" >> $RUN_C + [ -n "$sysname" ] && echo "sysName $sysname" >> $CONFIGFILE config_get sysservice "$cfg" sysService - [ -n "$sysservice" ] && echo "sysService $sysservice" >> $RUN_C + [ -n "$sysservice" ] && echo "sysService $sysservice" >> $CONFIGFILE config_get sysdescr "$cfg" sysDescr - [ -n "$sysdescr" ] && echo "sysDescr $sysdescr" >> $RUN_C + [ -n "$sysdescr" ] && echo "sysDescr $sysdescr" >> $CONFIGFILE config_get sysobjectid "$cfg" sysObjectID - [ -n "$sysobjectid" ] && echo "sysObjectID $sysobjectid" >> $RUN_C + [ -n "$sysobjectid" ] && echo "sysObjectID $sysobjectid" >> $CONFIGFILE } + snmpd_com2sec_add() { local cfg="$1" config_get secname "$cfg" secname @@ -37,8 +39,9 @@ snmpd_com2sec_add() { [ -n "$source" ] || return 0 config_get community "$cfg" community [ -n "$community" ] || return 0 - echo "com2sec $secname $source $community" >> $RUN_C + echo "com2sec $secname $source $community" >> $CONFIGFILE } + snmpd_com2sec6_add() { local cfg="$1" config_get secname "$cfg" secname @@ -47,8 +50,9 @@ snmpd_com2sec6_add() { [ -n "$source" ] || return 0 config_get community "$cfg" community [ -n "$community" ] || return 0 - echo "com2sec6 $secname $source $community" >> $RUN_C + echo "com2sec6 $secname $source $community" >> $CONFIGFILE } + snmpd_group_add() { local cfg="$1" config_get group "$cfg" group @@ -57,8 +61,9 @@ snmpd_group_add() { [ -n "$version" ] || return 0 config_get secname "$cfg" secname [ -n "$secname" ] || return 0 - echo "group $group $version $secname" >> $RUN_C + echo "group $group $version $secname" >> $CONFIGFILE } + snmpd_view_add() { local cfg="$1" config_get viewname "$cfg" viewname @@ -69,8 +74,9 @@ snmpd_view_add() { [ -n "$oid" ] || return 0 # optional mask config_get mask "$cfg" mask - echo "view $viewname $type $oid $mask" >> $RUN_C + echo "view $viewname $type $oid $mask" >> $CONFIGFILE } + snmpd_access_add() { local cfg="$1" config_get group "$cfg" group @@ -90,8 +96,9 @@ snmpd_access_add() { [ -n "$write" ] || return 0 config_get notify "$cfg" notify [ -n "$notify" ] || return 0 - echo "access $group $context $version $level $prefix $read $write $notify" >> $RUN_C + echo "access $group $context $version $level $prefix $read $write $notify" >> $CONFIGFILE } + snmpd_pass_add() { local cfg="$1" local pass='pass' @@ -104,8 +111,9 @@ snmpd_pass_add() { [ $persist -ne 0 ] && pass='pass_persist' config_get priority "$cfg" priority priority=${priority:+-p $priority} - echo "$pass $priority $miboid $prog" >> $RUN_C + echo "$pass $priority $miboid $prog" >> $CONFIGFILE } + snmpd_exec_add() { local cfg="$1" @@ -115,8 +123,9 @@ snmpd_exec_add() { [ -n "$prog" ] || return 0 config_get args "$cfg" args config_get miboid "$cfg" miboid - echo "exec $miboid $name $prog $args" >> $RUN_C + echo "exec $miboid $name $prog $args" >> $CONFIGFILE } + snmpd_disk_add() { local cfg="$1" local disk='disk' @@ -125,11 +134,11 @@ snmpd_disk_add() { [ -n "$partition" ] || return 0 config_get size "$cfg" size [ -n "$size" ] || return 0 - echo "$disk $partition $size" >> $RUN_C + echo "$disk $partition $size" >> $CONFIGFILE } start_service() { - [ -f "$RUN_C" ] && rm -f "$RUN_C" + [ -f "$CONFIGFILE" ] && rm -f "$CONFIGFILE" procd_open_instance @@ -147,12 +156,12 @@ start_service() { config_foreach snmpd_disk_add disk procd_set_param command $PROG -Lf /dev/null -f - procd_set_param file $RUN_C + procd_set_param file $CONFIGFILE procd_set_param respawn procd_close_instance } stop_service() { - [ -f "$RUN_C" ] && rm -f "$RUN_C" + [ -f "$CONFIGFILE" ] && rm -f "$CONFIGFILE" } From bee2865492fa8321a74627fd15a24c7caf54790d Mon Sep 17 00:00:00 2001 From: Stijn Tintel Date: Wed, 18 Feb 2015 06:03:54 +0100 Subject: [PATCH 4/4] net-snmp: monitor ifindex changes When an ifindex for an interface changes, some monitoring tools can no longer find the interface and send alerts. Monitor all network interfaces via the procd netdev parameter, so that /etc/init.d/snmpd reload will restart snmpd if any ifindex changed. Signed-off-by: Stijn Tintel --- net/net-snmp/files/snmpd.init | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/net/net-snmp/files/snmpd.init b/net/net-snmp/files/snmpd.init index a261447668..3dd8c41dc2 100644 --- a/net/net-snmp/files/snmpd.init +++ b/net/net-snmp/files/snmpd.init @@ -159,6 +159,10 @@ start_service() { procd_set_param file $CONFIGFILE procd_set_param respawn + for iface in $(ls /sys/class/net 2>/dev/null); do + procd_append_param netdev "$iface" + done + procd_close_instance }