vnstat2: update to version 2.12
This version includes several new features that allow to simplify the package significantly: The noexit patch and hotplug script are no longer needed, and the init script doesn't have to check for legacy databases anymore. Signed-off-by: Jan Hoffmann <jan@3e8.eu>
This commit is contained in:
parent
d1f674f38e
commit
94d74d3566
|
@ -6,12 +6,12 @@
|
||||||
include $(TOPDIR)/rules.mk
|
include $(TOPDIR)/rules.mk
|
||||||
|
|
||||||
PKG_NAME:=vnstat2
|
PKG_NAME:=vnstat2
|
||||||
PKG_VERSION:=2.11
|
PKG_VERSION:=2.12
|
||||||
PKG_RELEASE:=1
|
PKG_RELEASE:=1
|
||||||
|
|
||||||
PKG_SOURCE:=vnstat-$(PKG_VERSION).tar.gz
|
PKG_SOURCE:=vnstat-$(PKG_VERSION).tar.gz
|
||||||
PKG_SOURCE_URL:=https://humdi.net/vnstat
|
PKG_SOURCE_URL:=https://humdi.net/vnstat
|
||||||
PKG_HASH:=babc3f1583cc40e4e8ffb2f53296d93d308cb5a5043e85054f6eaf7b4ae57856
|
PKG_HASH:=b7386b12fc1fc6f47fab31f208b12eda61862e63e229e84e95a6fa80406d2852
|
||||||
|
|
||||||
PKG_LICENSE:=GPL-2.0-only
|
PKG_LICENSE:=GPL-2.0-only
|
||||||
PKG_LICENSE_FILES:=COPYING
|
PKG_LICENSE_FILES:=COPYING
|
||||||
|
@ -77,8 +77,6 @@ define Package/vnstat2/install
|
||||||
$(INSTALL_CONF) ./files/vnstat.config $(1)/etc/config/vnstat
|
$(INSTALL_CONF) ./files/vnstat.config $(1)/etc/config/vnstat
|
||||||
$(INSTALL_DIR) $(1)/etc/init.d
|
$(INSTALL_DIR) $(1)/etc/init.d
|
||||||
$(INSTALL_BIN) ./files/vnstat.init $(1)/etc/init.d/vnstat
|
$(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
|
endef
|
||||||
|
|
||||||
define Package/vnstati2/install
|
define Package/vnstati2/install
|
||||||
|
|
|
@ -1,23 +0,0 @@
|
||||||
/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
|
|
|
@ -5,26 +5,8 @@ STOP=50
|
||||||
|
|
||||||
USE_PROCD=1
|
USE_PROCD=1
|
||||||
|
|
||||||
vnstat_option() {
|
|
||||||
sed -ne "s/^[[:space:]]*$1[[:space:]]*['\"]\([^'\"]*\)['\"].*/\1/p" \
|
|
||||||
/etc/vnstat.conf
|
|
||||||
}
|
|
||||||
|
|
||||||
init_database() {
|
init_database() {
|
||||||
local lib database_count
|
/usr/sbin/vnstatd --initdb >/dev/null
|
||||||
|
|
||||||
lib="$(vnstat_option DatabaseDir)"
|
|
||||||
[ -n "$lib" ] || lib="/var/lib/vnstat"
|
|
||||||
|
|
||||||
database_count="$(ls "$lib" 2>/dev/null | wc -l)"
|
|
||||||
|
|
||||||
# only init database when folder is empty, as it would prevent import of legacy databases
|
|
||||||
if [ "$database_count" -eq "0" ]; then
|
|
||||||
/usr/sbin/vnstatd --initdb >/dev/null
|
|
||||||
else
|
|
||||||
# if vnstat.db doesn't exist, there are legacy databases to import
|
|
||||||
[ ! -f "$lib/vnstat.db" ] && echo -n "1"
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
init_ifaces() {
|
init_ifaces() {
|
||||||
|
@ -33,19 +15,14 @@ init_ifaces() {
|
||||||
init_iface() {
|
init_iface() {
|
||||||
local ifn="$1"
|
local ifn="$1"
|
||||||
|
|
||||||
/usr/bin/vnstat --add -i "$ifn" >/dev/null
|
/usr/bin/vnstat --add --force -i "$ifn" >/dev/null
|
||||||
}
|
}
|
||||||
|
|
||||||
config_list_foreach "$cfg" interface init_iface
|
config_list_foreach "$cfg" interface init_iface
|
||||||
}
|
}
|
||||||
|
|
||||||
start_service() {
|
start_service() {
|
||||||
local options needs_import
|
init_database
|
||||||
|
|
||||||
needs_import="$(init_database)"
|
|
||||||
|
|
||||||
# --noadd would prevent import of legacy databases
|
|
||||||
[ -z "$needs_import" ] && options="--noadd --noexit"
|
|
||||||
|
|
||||||
config_load vnstat
|
config_load vnstat
|
||||||
config_foreach init_ifaces vnstat
|
config_foreach init_ifaces vnstat
|
||||||
|
@ -53,7 +30,7 @@ start_service() {
|
||||||
procd_open_instance
|
procd_open_instance
|
||||||
procd_set_param stdout 1
|
procd_set_param stdout 1
|
||||||
procd_set_param stderr 1
|
procd_set_param stderr 1
|
||||||
procd_set_param command /usr/sbin/vnstatd --nodaemon $options
|
procd_set_param command /usr/sbin/vnstatd --nodaemon --noadd --startempty --noremove
|
||||||
procd_set_param file /etc/vnstat.conf
|
procd_set_param file /etc/vnstat.conf
|
||||||
procd_set_param respawn
|
procd_set_param respawn
|
||||||
procd_close_instance
|
procd_close_instance
|
||||||
|
|
|
@ -1,84 +0,0 @@
|
||||||
--- a/src/daemon.c
|
|
||||||
+++ b/src/daemon.c
|
|
||||||
@@ -277,6 +277,7 @@ void initdstate(DSTATE *s)
|
|
||||||
s->sync = 0;
|
|
||||||
s->forcesave = 0;
|
|
||||||
s->noadd = 0;
|
|
||||||
+ s->noexit = 0;
|
|
||||||
s->initdb = 0;
|
|
||||||
s->iflisthash = 0;
|
|
||||||
s->cfgfile[0] = '\0';
|
|
||||||
@@ -310,6 +311,9 @@ void preparedatabase(DSTATE *s)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (s->noadd) {
|
|
||||||
+ if (s->noexit) {
|
|
||||||
+ return;
|
|
||||||
+ }
|
|
||||||
printf("No interfaces found in database, exiting.\n");
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
@@ -328,6 +332,9 @@ void preparedatabase(DSTATE *s)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!addinterfaces(s) && s->dbifcount == 0) {
|
|
||||||
+ if (s->noexit) {
|
|
||||||
+ return;
|
|
||||||
+ }
|
|
||||||
printf("Nothing to do, exiting.\n");
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
--- a/src/daemon.h
|
|
||||||
+++ b/src/daemon.h
|
|
||||||
@@ -4,7 +4,7 @@
|
|
||||||
typedef struct {
|
|
||||||
int updateinterval, saveinterval;
|
|
||||||
short running, dodbsave, rundaemon;
|
|
||||||
- short dbsaved, showhelp, sync, forcesave, noadd, initdb;
|
|
||||||
+ short dbsaved, showhelp, sync, forcesave, noadd, noexit, initdb;
|
|
||||||
short bootdetected, cleanuphour, dbretrycount;
|
|
||||||
uint32_t iflisthash;
|
|
||||||
uint64_t dbifcount;
|
|
||||||
--- a/src/vnstatd.c
|
|
||||||
+++ b/src/vnstatd.c
|
|
||||||
@@ -259,6 +259,7 @@ void showhelp(void)
|
|
||||||
printf(" --config <config file> select used config file\n");
|
|
||||||
printf(" --noadd prevent startup if database has no interfaces\n");
|
|
||||||
printf(" --alwaysadd [mode] automatically start monitoring all new interfaces\n");
|
|
||||||
+ printf(" --noexit keep running even when database has no interfaces\n");
|
|
||||||
printf(" --initdb create empty database and exit\n\n");
|
|
||||||
|
|
||||||
printf("See also \"man vnstatd\".\n");
|
|
||||||
@@ -332,6 +333,8 @@ void parseargs(DSTATE *s, int argc, char
|
|
||||||
} else {
|
|
||||||
cfg.alwaysadd = 1;
|
|
||||||
}
|
|
||||||
+ } else if (strcmp(argv[currentarg], "--noexit") == 0) {
|
|
||||||
+ s->noexit = 1;
|
|
||||||
} else if (strcmp(argv[currentarg], "--initdb") == 0) {
|
|
||||||
s->initdb = 1;
|
|
||||||
s->showhelp = 0;
|
|
||||||
--- a/src/dbsql.c
|
|
||||||
+++ b/src/dbsql.c
|
|
||||||
@@ -976,7 +976,7 @@ int db_insertdata(const char *table, con
|
|
||||||
|
|
||||||
int db_removeoldentries(void)
|
|
||||||
{
|
|
||||||
- int rc, i;
|
|
||||||
+ int rc, i, dbifcount;
|
|
||||||
char sql[256];
|
|
||||||
const char *datatables[] = {"fiveminute", "hour", "day", "month", "year"};
|
|
||||||
const int32_t entrylimits[] = {cfg.fiveminutehours * 12, cfg.hourlydays * 24, cfg.dailydays, cfg.monthlymonths, cfg.yearlyyears};
|
|
||||||
@@ -987,8 +987,11 @@ int db_removeoldentries(void)
|
|
||||||
printf("db: removing old entries\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
- if (db_getiflist(&dbifl) <= 0) {
|
|
||||||
+ dbifcount = db_getiflist(&dbifl);
|
|
||||||
+ if (dbifcount < 0) {
|
|
||||||
return 0;
|
|
||||||
+ } else if (dbifcount == 0) {
|
|
||||||
+ return 1;
|
|
||||||
} else {
|
|
||||||
dbifl_i = dbifl;
|
|
||||||
}
|
|
Loading…
Reference in New Issue