diff --git a/periodicstats/Makefile b/periodicstats/Makefile new file mode 100644 index 000000000..1db28ff38 --- /dev/null +++ b/periodicstats/Makefile @@ -0,0 +1,52 @@ +# +# Copyright (C) 2020 IOPSYS +# + +include $(TOPDIR)/rules.mk +include $(INCLUDE_DIR)/kernel.mk + +PKG_NAME:=periodicstats +PKG_VERSION:=1.0.0 + +LOCAL_DEV:=0 +ifneq ($(LOCAL_DEV),1) +PKG_SOURCE_PROTO:=git +PKG_SOURCE_VERSION:=91b15f9779baccc93213ce3ca164c326235d3096 +PKG_SOURCE_URL:=https://dev.iopsys.eu/iopsys/periodicstats.git +PKG_SOURCE:=$(PKG_NAME)-$(PKG_SOURCE_VERSION).tar.gz +endif + +PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION) +PKG_LICENSE:=GPL-2.0-only +PKG_LICENSE_FILES:=LICENSE + +include $(INCLUDE_DIR)/package.mk + +define Package/periodicstats + SECTION:=utils + CATEGORY:=Utilities + TITLE:=Periodic Statistics Daemon + DEPENDS:=+libuci +libubox +libubus +libblobmsg-json +libjson-c +libbbfdm +endef + +define Package/periodicstats/description + Manage periodic statistics +endef + +ifeq ($(LOCAL_DEV),1) +define Build/Prepare + $(CP) -rf ./periodicstats/* $(PKG_BUILD_DIR)/ +endef +endif + +define Package/periodicstats/install + $(CP) ./files/* $(1)/ + $(INSTALL_DIR) $(1)/usr + $(INSTALL_DIR) $(1)/usr/sbin + $(INSTALL_DIR) $(1)/usr/lib + $(INSTALL_DIR) $(1)/usr/lib/bbfdm + $(CP) $(PKG_BUILD_DIR)/bbf_plugin/libperiodicstats.so $(1)/usr/lib/bbfdm + $(INSTALL_BIN) $(PKG_BUILD_DIR)/periodicstatsd $(1)/usr/sbin +endef + +$(eval $(call BuildPackage,periodicstats)) diff --git a/periodicstats/files/etc/config/periodicstats b/periodicstats/files/etc/config/periodicstats new file mode 100644 index 000000000..133edaffe --- /dev/null +++ b/periodicstats/files/etc/config/periodicstats @@ -0,0 +1,3 @@ +config globals 'globals' + option enable '0' + diff --git a/periodicstats/files/etc/init.d/periodicstats b/periodicstats/files/etc/init.d/periodicstats new file mode 100755 index 000000000..06b389bcd --- /dev/null +++ b/periodicstats/files/etc/init.d/periodicstats @@ -0,0 +1,43 @@ +#!/bin/sh /etc/rc.common + +START=99 +STOP=10 + +USE_PROCD=1 +NAME=periodicstatsd +PROG=/usr/sbin/periodicstatsd + +. /lib/functions.sh + +start_service() { + if [ -f "/etc/config/periodicstats" ]; then + if [ "$(uci -q get periodicstats.globals.enable)" == "1" ]; then + procd_open_instance periodicstatsd + procd_set_param command ${PROG} + procd_set_param respawn + procd_close_instance + fi + fi +} + +stop() { + #stop_service() is called after procd killed the service + echo ; +} + +boot() { + start +} + +service_triggers() { + procd_add_reload_trigger periodicstats +} + +reload_service() { + stop + start +} + +restart() { + start +}