mirror of
https://dev.iopsys.eu/feed/iopsys.git
synced 2025-12-10 07:44:50 +01:00
97 lines
2.2 KiB
Bash
97 lines
2.2 KiB
Bash
#!/bin/sh /etc/rc.common
|
|
|
|
START=65
|
|
STOP=10
|
|
|
|
USE_PROCD=1
|
|
PROG=/usr/sbin/bbfdmd
|
|
|
|
BBFDM_JSON_INPUT="/etc/bbfdm/input.json"
|
|
BBFDM_TEMP_JSON="/tmp/bbfdm.json"
|
|
|
|
log() {
|
|
echo "${@}"|logger -t bbfdmd.init -p info
|
|
}
|
|
|
|
validate_bbfdm_bbfdmd_section()
|
|
{
|
|
uci_validate_section bbfdm bbfdmd "bbfdmd" \
|
|
'enabled:bool:true' \
|
|
'sock:string' \
|
|
'debug:bool:false' \
|
|
'loglevel:uinteger:1' \
|
|
'refresh_time:uinteger:0' \
|
|
'transaction_timeout:uinteger:30' \
|
|
'subprocess_level:uinteger'
|
|
}
|
|
|
|
configure_bbfdmd()
|
|
{
|
|
local enabled debug sock update
|
|
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
|
|
[ ! -f "${BBFDM_JSON_INPUT}" ] && return 0
|
|
|
|
jlog="$(jq '.daemon.config.loglevel' ${BBFDM_JSON_INPUT})"
|
|
if [ "\"${loglevel}\"" != "${jlog}" ]; then
|
|
update=1
|
|
fi
|
|
|
|
jrefresh="$(jq '.daemon.config.refresh_time' ${BBFDM_JSON_INPUT})"
|
|
if [ "\"${refresh_time}\"" != "${jrefresh}" ]; then
|
|
update=1
|
|
fi
|
|
|
|
jtimeout="$(jq '.daemon.config.transaction_timeout' ${BBFDM_JSON_INPUT})"
|
|
if [ "\"${transaction_timeout}\"" != "${jtimeout}" ]; then
|
|
update=1
|
|
fi
|
|
|
|
jlevel="$(jq '.daemon.config.subprocess_level' ${BBFDM_JSON_INPUT})"
|
|
if [ "\"${subprocess_level}\"" != "${jlevel}" ]; then
|
|
update=1
|
|
fi
|
|
|
|
if [ "${update}" -eq "1" ]; 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}
|
|
mv ${BBFDM_TEMP_JSON} ${BBFDM_JSON_INPUT}
|
|
fi
|
|
|
|
procd_set_param command ${PROG}
|
|
if [ "${debug}" -eq 1 ]; then
|
|
procd_set_param stdout 1
|
|
procd_set_param stderr 1
|
|
fi
|
|
|
|
if [ -f "${sock}" ]; then
|
|
procd_append_param command -s "${sock}"
|
|
fi
|
|
}
|
|
|
|
start_service()
|
|
{
|
|
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()
|
|
{
|
|
ubus call service state '{"name":"bbfdm.services", "spawn":false}'
|
|
}
|
|
|
|
service_triggers()
|
|
{
|
|
procd_add_reload_trigger "bbfdm"
|
|
}
|