Skip to content
Snippets Groups Projects
Commit a58b0477 authored by Vivek Dutta's avatar Vivek Dutta
Browse files

bbfdm: Added micro_service uci

parent 9ef7c35e
No related branches found
No related tags found
1 merge request!968bbfdm: Bbfdm microservice uci
...@@ -5,13 +5,13 @@ ...@@ -5,13 +5,13 @@
include $(TOPDIR)/rules.mk include $(TOPDIR)/rules.mk
PKG_NAME:=bbfdm PKG_NAME:=bbfdm
PKG_VERSION:=1.7.9 PKG_VERSION:=1.7.10
USE_LOCAL:=0 USE_LOCAL:=0
ifneq ($(USE_LOCAL),1) ifneq ($(USE_LOCAL),1)
PKG_SOURCE_PROTO:=git PKG_SOURCE_PROTO:=git
PKG_SOURCE_URL:=https://dev.iopsys.eu/bbf/bbfdm.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_SOURCE:=$(PKG_NAME)-$(PKG_VERSION)-$(PKG_SOURCE_VERSION).tar.gz
PKG_MIRROR_HASH:=skip PKG_MIRROR_HASH:=skip
endif endif
...@@ -107,6 +107,8 @@ define Package/libbbfdm/install ...@@ -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/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/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/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.portmap $(1)/etc/firewall.portmap
$(INSTALL_BIN) ./files/etc/firewall.service $(1)/etc/firewall.service $(INSTALL_BIN) ./files/etc/firewall.service $(1)/etc/firewall.service
ifeq ($(findstring iopsys,$(CONFIG_BBF_VENDOR_LIST)),iopsys) ifeq ($(findstring iopsys,$(CONFIG_BBF_VENDOR_LIST)),iopsys)
......
...@@ -14,6 +14,7 @@ bbfdm_add_service() ...@@ -14,6 +14,7 @@ bbfdm_add_service()
fi fi
ubus call service add "{'name':'bbfdm.services','instances':{'$name':{'command':['$BBFDMD','-m','$path']}}}" 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() bbfdm_stop_service()
......
config bbfdmd 'bbfdmd' config bbfdmd 'bbfdmd'
option enabled '1' option enable '1'
option loglevel '1' option loglevel '1'
option refresh_time '10' option refresh_time '10'
option transaction_timeout '30' option transaction_timeout '30'
option subprocess_level '2' option subprocess_level '2'
...@@ -7,7 +7,7 @@ USE_PROCD=1 ...@@ -7,7 +7,7 @@ USE_PROCD=1
PROG=/usr/sbin/bbfdmd PROG=/usr/sbin/bbfdmd
BBFDM_JSON_INPUT="/etc/bbfdm/input.json" BBFDM_JSON_INPUT="/etc/bbfdm/input.json"
BBFDM_TEMP_JSON="/tmp/bbfdm/input.json" BBFDM_TEMP_DIR="/tmp/bbfdm"
log() { log() {
echo "${@}"|logger -t bbfdmd.init -p info echo "${@}"|logger -t bbfdmd.init -p info
...@@ -16,7 +16,7 @@ log() { ...@@ -16,7 +16,7 @@ log() {
validate_bbfdm_bbfdmd_section() validate_bbfdm_bbfdmd_section()
{ {
uci_validate_section bbfdm bbfdmd "bbfdmd" \ uci_validate_section bbfdm bbfdmd "bbfdmd" \
'enabled:bool:true' \ 'enable:bool:true' \
'sock:string' \ 'sock:string' \
'debug:bool:false' \ 'debug:bool:false' \
'loglevel:uinteger:1' \ 'loglevel:uinteger:1' \
...@@ -25,22 +25,76 @@ validate_bbfdm_bbfdmd_section() ...@@ -25,22 +25,76 @@ validate_bbfdm_bbfdmd_section()
'subprocess_level:uinteger' '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() configure_bbfdmd()
{ {
local enabled debug sock update local enable debug sock
local jlog jrefresh jtimeout jlevel local jlog jrefresh jtimeout jlevel
update=0
config_load bbfdm config_load bbfdm
validate_bbfdm_bbfdmd_section || { validate_bbfdm_bbfdmd_section || {
log "Validation of bbfdmd section failed" log "Validation of bbfdmd section failed"
return 1; return 1;
} }
[ "${enabled}" -eq 0 ] && return 0 [ "${enable}" -eq 0 ] && return 0
if [ -f "${BBFDM_JSON_INPUT}" ]; then 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 fi
procd_set_param command ${PROG} procd_set_param command ${PROG}
...@@ -56,13 +110,14 @@ configure_bbfdmd() ...@@ -56,13 +110,14 @@ configure_bbfdmd()
start_service() start_service()
{ {
mkdir -p /tmp/bbfdm mkdir -p ${BBFDM_TEMP_DIR}
configure_bbfdm_micro_services
procd_open_instance "bbfdm" procd_open_instance "bbfdm"
configure_bbfdmd configure_bbfdmd
procd_set_param respawn procd_set_param respawn
procd_close_instance "bbfdm" procd_close_instance "bbfdm"
ubus call service state '{"name":"bbfdm.services", "spawn":true}'
} }
stop_service() stop_service()
......
#!/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
#!/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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment