diff --git a/bbfdm/Makefile b/bbfdm/Makefile index 4516cf64c338094992e84f09a9468cbaec8f949c..0579a578f4778898128be4d1d213f43495d56f54 100644 --- a/bbfdm/Makefile +++ b/bbfdm/Makefile @@ -5,13 +5,13 @@ include $(TOPDIR)/rules.mk PKG_NAME:=bbfdm -PKG_VERSION:=1.7.9 +PKG_VERSION:=1.7.10 USE_LOCAL:=0 ifneq ($(USE_LOCAL),1) PKG_SOURCE_PROTO:=git PKG_SOURCE_URL:=https://dev.iopsys.eu/bbf/bbfdm.git -PKG_SOURCE_VERSION:=ec0fba3fb5a3651b628aa0b97d2216c1cdc6a9e8 +PKG_SOURCE_VERSION:=0f8a98b500d5d0c24729496ddb395599a229768b PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION)-$(PKG_SOURCE_VERSION).tar.gz PKG_MIRROR_HASH:=skip endif @@ -107,6 +107,8 @@ define Package/libbbfdm/install $(INSTALL_BIN) ./files/etc/uci-defaults/95-portmap-firewall $(1)/etc/uci-defaults/95-portmap-firewall $(INSTALL_BIN) ./files/etc/uci-defaults/97-firewall-service $(1)/etc/uci-defaults/97-firewall-service $(INSTALL_BIN) ./files/etc/uci-defaults/99-link-core-plugins $(1)/etc/uci-defaults/99-link-core-plugins + $(INSTALL_BIN) ./files/etc/uci-defaults/90-remove-nonexisting-microservices $(1)/etc/uci-defaults/ + $(INSTALL_BIN) ./files/etc/uci-defaults/91-fix-bbfdmd-enabled-option $(1)/etc/uci-defaults/ $(INSTALL_BIN) ./files/etc/firewall.portmap $(1)/etc/firewall.portmap $(INSTALL_BIN) ./files/etc/firewall.service $(1)/etc/firewall.service ifeq ($(findstring iopsys,$(CONFIG_BBF_VENDOR_LIST)),iopsys) diff --git a/bbfdm/files/etc/bbfdm/bbfdm_services.sh b/bbfdm/files/etc/bbfdm/bbfdm_services.sh index 003a48660261a31477bb8feaea38856e44fbceec..b7361230edfa459d53524e6937bb8745b66fd3e2 100755 --- a/bbfdm/files/etc/bbfdm/bbfdm_services.sh +++ b/bbfdm/files/etc/bbfdm/bbfdm_services.sh @@ -14,6 +14,7 @@ bbfdm_add_service() fi ubus call service add "{'name':'bbfdm.services','instances':{'$name':{'command':['$BBFDMD','-m','$path']}}}" + echo "Use of bbfdm_add_service deprecated, please use bbfdm micro_service uci" } bbfdm_stop_service() diff --git a/bbfdm/files/etc/config/bbfdm b/bbfdm/files/etc/config/bbfdm index cedc444f8612166c8c11baa9c4c1dff9b521cb94..df3fe32fdcf34c68e8dcfff88e5544d023c53901 100644 --- a/bbfdm/files/etc/config/bbfdm +++ b/bbfdm/files/etc/config/bbfdm @@ -1,8 +1,6 @@ - config bbfdmd 'bbfdmd' - option enabled '1' + option enable '1' option loglevel '1' option refresh_time '10' option transaction_timeout '30' option subprocess_level '2' - diff --git a/bbfdm/files/etc/init.d/bbfdmd b/bbfdm/files/etc/init.d/bbfdmd index 2b9d96f8850b0ddfd0ffa2d3b318db41b3f77855..4e5441216baa102895876c4e651f53871230708f 100644 --- a/bbfdm/files/etc/init.d/bbfdmd +++ b/bbfdm/files/etc/init.d/bbfdmd @@ -7,7 +7,7 @@ USE_PROCD=1 PROG=/usr/sbin/bbfdmd BBFDM_JSON_INPUT="/etc/bbfdm/input.json" -BBFDM_TEMP_JSON="/tmp/bbfdm/input.json" +BBFDM_TEMP_DIR="/tmp/bbfdm" log() { echo "${@}"|logger -t bbfdmd.init -p info @@ -16,7 +16,7 @@ log() { validate_bbfdm_bbfdmd_section() { uci_validate_section bbfdm bbfdmd "bbfdmd" \ - 'enabled:bool:true' \ + 'enable:bool:true' \ 'sock:string' \ 'debug:bool:false' \ 'loglevel:uinteger:1' \ @@ -25,22 +25,76 @@ validate_bbfdm_bbfdmd_section() 'subprocess_level:uinteger' } +validate_bbfdm_micro_service_section() +{ + uci_validate_section bbfdm micro_service "${1}" \ + 'enable:bool:true' \ + 'loglevel:uinteger:1' \ + 'input_json:string' +} + +bbfdm_add_micro_service() +{ + local name path + + name="${1}" + path="${BBFDM_TEMP_DIR}/${name}.json" + + if [ -z "${name}" ]; then + log "micro-service name not defined" + return 0; + fi + + if [ ! -f "$path" ]; then + log "micro-service input file not present" + return 0; + fi + + ubus call service add "{'name':'bbfdm.services','instances':{'$name':{'command':['${PROG}','-m','$path']}}}" +} + +_add_microservice() +{ + local enable loglevel input_json name + + validate_bbfdm_micro_service_section "${1}" || { + log "validation of bbfdm micro_service $1 failed" + return 1; + } + + name="${1}" + [ "${enable}" -eq 0 ] && return 0 + + if [ -f "${input_json}" ]; then + echo "$(jq --arg log ${loglevel} '.daemon.config += {"loglevel": $log }' ${input_json})" > "${BBFDM_TEMP_DIR}/${name}.json" + bbfdm_add_micro_service "${name}" + fi + +} + +configure_bbfdm_micro_services() +{ + config_load bbfdm + config_foreach _add_microservice "micro_service" + + ubus call service state '{"name":"bbfdm.services", "spawn":true}' +} + configure_bbfdmd() { - local enabled debug sock update + local enable debug sock local jlog jrefresh jtimeout jlevel - update=0 config_load bbfdm validate_bbfdm_bbfdmd_section || { log "Validation of bbfdmd section failed" return 1; } - [ "${enabled}" -eq 0 ] && return 0 + [ "${enable}" -eq 0 ] && return 0 if [ -f "${BBFDM_JSON_INPUT}" ]; then - echo "$(jq --arg log ${loglevel} --arg tran ${transaction_timeout} --arg refresh ${refresh_time} --arg level ${subprocess_level} '.daemon.config += {"loglevel": $log, "refresh_time": $refresh, "transaction_timeout": $tran, "subprocess_level": $level}' ${BBFDM_JSON_INPUT})" > ${BBFDM_TEMP_JSON} + echo "$(jq --arg log ${loglevel} --arg tran ${transaction_timeout} --arg refresh ${refresh_time} --arg level ${subprocess_level} '.daemon.config += {"loglevel": $log, "refresh_time": $refresh, "transaction_timeout": $tran, "subprocess_level": $level}' ${BBFDM_JSON_INPUT})" > "${BBFDM_TEMP_DIR}/input.json" fi procd_set_param command ${PROG} @@ -56,13 +110,14 @@ configure_bbfdmd() start_service() { - mkdir -p /tmp/bbfdm + mkdir -p ${BBFDM_TEMP_DIR} + + configure_bbfdm_micro_services + procd_open_instance "bbfdm" configure_bbfdmd procd_set_param respawn procd_close_instance "bbfdm" - - ubus call service state '{"name":"bbfdm.services", "spawn":true}' } stop_service() diff --git a/bbfdm/files/etc/uci-defaults/90-remove-nonexisting-microservices b/bbfdm/files/etc/uci-defaults/90-remove-nonexisting-microservices new file mode 100644 index 0000000000000000000000000000000000000000..40eed3d5501e3139fc2692bae691b8dbc737a682 --- /dev/null +++ b/bbfdm/files/etc/uci-defaults/90-remove-nonexisting-microservices @@ -0,0 +1,18 @@ +#!/bin/sh +. /lib/functions.sh + +remove_nonexisting_microservice() { + local input_json + + config_get input_json "$1" input_json "" + + if [ -z "${input_json}" ]; then + uci_remove bbfdm "${1}" + fi +} + +config_load bbfdm +config_foreach remove_nonexisting_microservice "micro_service" + +exit 0 + diff --git a/bbfdm/files/etc/uci-defaults/91-fix-bbfdmd-enabled-option b/bbfdm/files/etc/uci-defaults/91-fix-bbfdmd-enabled-option new file mode 100644 index 0000000000000000000000000000000000000000..e18c871c1432831928f91b9994bd3945c6915c2c --- /dev/null +++ b/bbfdm/files/etc/uci-defaults/91-fix-bbfdmd-enabled-option @@ -0,0 +1,11 @@ +#!/bin/sh + +# rename bbfdmd enabled option to enable +val="$(uci -q get bbfdm.bbfdmd.enabled)" +if [ -n "${val}" ]; then + uci -q set bbfdm.bbfdmd.enabled="" + uci -q set bbfdm.bbfdmd.enable="${val}" +fi + +exit 0 +