From e1acbd55b6e7bb479d1a1c36c0d9b19feb61b668 Mon Sep 17 00:00:00 2001 From: Martin Blumenstingl Date: Sun, 23 Jul 2017 11:59:01 +0200 Subject: [PATCH 1/2] net/vnstat: port the init-script to procd This ports the init-script from the legacy functions to procd. There should be no functional changes with this patch. Signed-off-by: Martin Blumenstingl --- net/vnstat/files/vnstat.init | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/net/vnstat/files/vnstat.init b/net/vnstat/files/vnstat.init index 7921cbcde..cc9cdc7cc 100644 --- a/net/vnstat/files/vnstat.init +++ b/net/vnstat/files/vnstat.init @@ -3,25 +3,21 @@ START=99 +USE_PROCD=1 + vnstat_option() { sed -ne "s/^[[:space:]]*$1[[:space:]]*['\"]\([^'\"]*\)['\"].*/\1/p" \ /etc/vnstat.conf } -start() { +start_service() { local lib="$(vnstat_option DatabaseDir)" - local pid="$(vnstat_option PidFile)" [ -n "$lib" ] || { echo "Error: No DatabaseDir set in vnstat.conf" >&2 exit 1 } - [ -n "$pid" ] || { - echo "Error: No PidFile set in vnstat.conf" >&2 - exit 1 - } - mkdir -p "$lib" init_ifaces() { @@ -72,18 +68,18 @@ start() { config_load vnstat config_foreach init_ifaces vnstat - SERVICE_PID_FILE="${pid}" - service_start /usr/sbin/vnstatd -d + procd_open_instance + procd_set_param stdout 1 + procd_set_param stderr 1 + procd_set_param command /usr/sbin/vnstatd --nodaemon + procd_set_param file /etc/vnstat.conf + procd_close_instance } -stop() { - local pid="$(vnstat_option PidFile)" - - [ -n "$pid" ] || { - echo "Error: No PidFile set in vnstat.conf" >&2 - exit 1 - } +reload_service() { + procd_send_signal vnstat +} - SERVICE_PID_FILE="${pid}" - service_stop /usr/sbin/vnstatd +service_triggers() { + procd_add_reload_trigger vnstat } From 96ae89c8014e6bfff61797c031f8c8e7f45b98f8 Mon Sep 17 00:00:00 2001 From: Martin Blumenstingl Date: Sun, 23 Jul 2017 12:01:10 +0200 Subject: [PATCH 2/2] net/vnstat: enable auto-respawn when vnstatd crashes Originally this was indended as a fix for devices without RTC support which do not have the correct time set after a reboot (until ntp is able to update the system time). vnstat checks if there is a time difference between the latest entry in the database and detects that the system time is incorrect. In this case vnstat does not start (to prevent database corruption), the following message is reported instead: 'Error: Interface "..." has previous update date too much in the future, exiting.' Once we have network connectivity (and ntp has updated the system time) vnstat starts correctly though. vnstat 1.18 fixes this by waiting a few minutes (instead of exiting) and the following message is logged: "Latest database update is in the future (db: 2018-04-28 08:39:11 > now: 2018-04-28 08:07:18). Giving the system clock up to 5 minutes to sync before continuing." This still adds a procd respawn trigger to let procd automatically restart vnstat in case: - vnstat it crashes - no valid system time is received for a long time (no network connectivity, broken NTP servers, ...) Signed-off-by: Martin Blumenstingl --- net/vnstat/Makefile | 2 +- net/vnstat/files/vnstat.init | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/net/vnstat/Makefile b/net/vnstat/Makefile index 1a526fd92..e69b5b036 100644 --- a/net/vnstat/Makefile +++ b/net/vnstat/Makefile @@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=vnstat PKG_VERSION:=1.18 -PKG_RELEASE:=1 +PKG_RELEASE:=2 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz PKG_SOURCE_URL:=http://humdi.net/vnstat diff --git a/net/vnstat/files/vnstat.init b/net/vnstat/files/vnstat.init index cc9cdc7cc..bfd99f8ae 100644 --- a/net/vnstat/files/vnstat.init +++ b/net/vnstat/files/vnstat.init @@ -73,6 +73,7 @@ start_service() { procd_set_param stderr 1 procd_set_param command /usr/sbin/vnstatd --nodaemon procd_set_param file /etc/vnstat.conf + procd_set_param respawn procd_close_instance }