bbfdm: option to add respawn and core for microservice

This commit is contained in:
Vivek Kumar Dutta 2024-03-20 19:42:47 +05:30
parent b0ea1a6a53
commit a1b4b34b39
3 changed files with 56 additions and 4 deletions

View file

@ -5,7 +5,7 @@
include $(TOPDIR)/rules.mk include $(TOPDIR)/rules.mk
PKG_NAME:=bbfdm PKG_NAME:=bbfdm
PKG_VERSION:=1.7.17 PKG_VERSION:=1.7.18
USE_LOCAL:=0 USE_LOCAL:=0
ifneq ($(USE_LOCAL),1) ifneq ($(USE_LOCAL),1)

View file

@ -4,3 +4,8 @@ config bbfdmd 'bbfdmd'
option refresh_time '10' option refresh_time '10'
option transaction_timeout '30' option transaction_timeout '30'
option subprocess_level '2' option subprocess_level '2'
config micro_services 'micro_services'
option enable '1'
option enable_core '0'
option enable_respawn '1'

View file

@ -10,6 +10,8 @@ BBFDM_JSON_INPUT="/etc/bbfdm/input.json"
BBFDM_MICROSERVICE_DIR="/etc/bbfdm/micro_services" BBFDM_MICROSERVICE_DIR="/etc/bbfdm/micro_services"
BBFDM_TEMP_DIR="/tmp/bbfdm" BBFDM_TEMP_DIR="/tmp/bbfdm"
. /usr/share/libubox/jshn.sh
log() { log() {
echo "${@}"|logger -t bbfdmd.init -p info echo "${@}"|logger -t bbfdmd.init -p info
} }
@ -26,15 +28,60 @@ validate_bbfdm_bbfdmd_section()
'subprocess_level:uinteger' 'subprocess_level:uinteger'
} }
validate_bbfdm_micro_service_section()
{
uci_validate_section bbfdm micro_services "micro_services" \
'enable:bool:true' \
'enable_core:bool:false' \
'enable_respawn:bool:true'
}
bbfdm_add_micro_service() bbfdm_add_micro_service()
{ {
local name path local name path cmd
local enable enable_core enable_respawn
validate_bbfdm_micro_service_section || {
log "Validation of micro_service section failed"
return 1;
}
[ "${enable}" -eq "0" ] && return 0
path="${1}" path="${1}"
name="$(basename ${path})" name="$(basename ${path})"
name="${name//.json}" name="${name//.json}"
ubus call service add "{'name':'bbfdm.services','instances':{'$name':{'command':['${PROG}','-m','$path']}}}" json_init
json_add_string name "bbfdm.services"
json_add_object "instances"
json_add_object "${name}"
json_add_array "command"
json_add_string "" "${PROG}"
json_add_string "" "-m"
json_add_string "" "${path}"
json_close_array
if [ "${enable_core}" -eq "1" ]; then
json_add_object "limits"
json_add_string "core" "unlimited"
json_close_object
json_add_boolean "stdout" 1
json_add_boolean "stderr" 1
fi
if [ "${enable_respawn}" -eq "1" ]; then
json_add_array "respawn"
json_add_string "" "3600"
json_add_string "" "5"
json_add_string "" "5"
json_close_array
fi
json_close_object
json_close_object
cmd="$(json_dump)"
ubus call service add "${cmd}"
} }
_add_microservice() _add_microservice()
@ -108,7 +155,7 @@ start_service()
stop_service() stop_service()
{ {
ubus call service state '{"name":"bbfdm.services", "spawn":false}' ubus call service delete '{"name":"bbfdm.services"}'
} }
service_triggers() service_triggers()