vnstat2: add hotplug script for adding interfaces
authorJan Hoffmann <redacted>
Wed, 27 Oct 2021 21:55:28 +0000 (23:55 +0200)
committerRosen Penev <redacted>
Thu, 28 Oct 2021 08:31:18 +0000 (01:31 -0700)
If an interface doesn't exist yet when vnStat is started, it won't be
monitored, as only existing interfaces can be added to the database via
the vnstat command.

This adds a hotplug script which adds any configured interfaces to the
vnStat database when it goes up.

Signed-off-by: Jan Hoffmann <redacted>
net/vnstat2/Makefile
net/vnstat2/files/vnstat.hotplug [new file with mode: 0644]

index eadd0c67159e233364701c6efce6407801890cb7..3f31083ec7f6e75f8f051303fa3aefc3a9c59379 100644 (file)
@@ -77,6 +77,8 @@ define Package/vnstat2/install
        $(INSTALL_CONF) ./files/vnstat.config $(1)/etc/config/vnstat
        $(INSTALL_DIR) $(1)/etc/init.d
        $(INSTALL_BIN) ./files/vnstat.init $(1)/etc/init.d/vnstat
+       $(INSTALL_DIR) $(1)/etc/hotplug.d/iface
+       $(INSTALL_DATA) ./files/vnstat.hotplug $(1)/etc/hotplug.d/iface/50-vnstat
 endef
 
 define Package/vnstati2/install
diff --git a/net/vnstat2/files/vnstat.hotplug b/net/vnstat2/files/vnstat.hotplug
new file mode 100644 (file)
index 0000000..339c0ac
--- /dev/null
@@ -0,0 +1,23 @@
+/etc/init.d/vnstat running || exit 0
+[ "$ACTION" = "ifup" ] || exit 0
+
+. /lib/functions.sh
+
+check_iface() {
+       local iface="$1"
+
+       [ "$iface" = "$DEVICE" ] || return
+
+       /usr/bin/vnstat --add -i "$iface" >/dev/null
+
+       exit 0
+}
+
+check_ifaces() {
+       local cfg="$1"
+
+       config_list_foreach "$cfg" interface check_iface
+}
+
+config_load vnstat
+config_foreach check_ifaces vnstat
git clone https://git.99rst.org/PROJECT