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

bbfdm: option to add respawn and core for microservice

parent b0ea1a6a
Branches
No related tags found
No related merge requests found
......@@ -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)
......
......@@ -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'
......@@ -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()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment