mirror of
https://dev.iopsys.eu/feed/iopsys.git
synced 2025-12-10 07:44:50 +01:00
bbfdm: Added micro_service uci
This commit is contained in:
parent
9ef7c35ee0
commit
a58b047723
6 changed files with 99 additions and 14 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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'
|
||||
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
11
bbfdm/files/etc/uci-defaults/91-fix-bbfdmd-enabled-option
Normal file
11
bbfdm/files/etc/uci-defaults/91-fix-bbfdmd-enabled-option
Normal file
|
|
@ -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
|
||||
|
||||
Loading…
Add table
Reference in a new issue