diff --git a/bbfdm/Makefile b/bbfdm/Makefile index 438d743ba9d94fa9326319aac80ed973aaacd56d..e328868a57ee37a7600278ba54991b809886a4eb 100644 --- a/bbfdm/Makefile +++ b/bbfdm/Makefile @@ -5,7 +5,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=bbfdm -PKG_VERSION:=1.7.17 +PKG_VERSION:=1.7.18 USE_LOCAL:=0 ifneq ($(USE_LOCAL),1) diff --git a/bbfdm/files/etc/config/bbfdm b/bbfdm/files/etc/config/bbfdm index df3fe32fdcf34c68e8dcfff88e5544d023c53901..dc970499dfc5f7f2611a2aa33de203dc5c51ceb1 100644 --- a/bbfdm/files/etc/config/bbfdm +++ b/bbfdm/files/etc/config/bbfdm @@ -4,3 +4,8 @@ config bbfdmd 'bbfdmd' option refresh_time '10' option transaction_timeout '30' option subprocess_level '2' + +config micro_services 'micro_services' + option enable '1' + option enable_core '0' + option enable_respawn '1' diff --git a/bbfdm/files/etc/init.d/bbfdmd b/bbfdm/files/etc/init.d/bbfdmd index 4c1547a2dd8e88d96fd9059a6e9212d1f9985e96..82a41cb0ca33cbeef08877585cf041a83253e277 100644 --- a/bbfdm/files/etc/init.d/bbfdmd +++ b/bbfdm/files/etc/init.d/bbfdmd @@ -10,6 +10,8 @@ BBFDM_JSON_INPUT="/etc/bbfdm/input.json" BBFDM_MICROSERVICE_DIR="/etc/bbfdm/micro_services" BBFDM_TEMP_DIR="/tmp/bbfdm" +. /usr/share/libubox/jshn.sh + log() { echo "${@}"|logger -t bbfdmd.init -p info } @@ -26,15 +28,60 @@ validate_bbfdm_bbfdmd_section() '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() { - 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}" name="$(basename ${path})" 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() @@ -108,7 +155,7 @@ start_service() stop_service() { - ubus call service state '{"name":"bbfdm.services", "spawn":false}' + ubus call service delete '{"name":"bbfdm.services"}' } service_triggers()