mirror of
https://dev.iopsys.eu/feed/iopsys.git
synced 2025-12-10 07:44:50 +01:00
obuspa: Fix startup validations
- Fix validations in init script for the uci config - Dump outgoing events in logs, if configured - static code warning fixes
This commit is contained in:
parent
f126ed414a
commit
54010769ed
2 changed files with 72 additions and 41 deletions
|
|
@ -5,12 +5,12 @@
|
|||
include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_NAME:=obuspa
|
||||
PKG_VERSION:=5.0.0.2
|
||||
PKG_VERSION:=5.0.0.3
|
||||
|
||||
LOCAL_DEV:=0
|
||||
ifneq ($(LOCAL_DEV),1)
|
||||
PKG_SOURCE_PROTO:=git
|
||||
PKG_SOURCE_VERSION:=0afaf5eeed63dceb275d7715ccce8977cfad1ee3
|
||||
PKG_SOURCE_VERSION:=9d957848b9ac1d381149ce43b59775c21b1e24e0
|
||||
PKG_SOURCE_URL:=https://dev.iopsys.eu/fork/obuspa.git
|
||||
PKG_MAINTAINER:=Vivek Dutta <vivek.dutta@iopsys.eu>
|
||||
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION)-$(PKG_SOURCE_VERSION).tar.gz
|
||||
|
|
|
|||
|
|
@ -223,6 +223,19 @@ validate_mqtt_client_section()
|
|||
'ConnectRetryMaxInterval:uinteger:60'
|
||||
}
|
||||
|
||||
validate_challenge_section()
|
||||
{
|
||||
uci_validate_section ${CONFIGURATION} challenge "${1}" \
|
||||
'Enable:bool:true' \
|
||||
'Alias:string' \
|
||||
'Description:string' \
|
||||
'role_name:string' \
|
||||
'Role:string' \
|
||||
'Value:string' \
|
||||
'Retries:uinteger:3' \
|
||||
'LockoutPeriod:uinteger:0'
|
||||
}
|
||||
|
||||
get_oui_from_db() {
|
||||
db -q get device.deviceinfo.ManufacturerOUI
|
||||
}
|
||||
|
|
@ -233,7 +246,11 @@ get_serial_from_db() {
|
|||
|
||||
publish_endpoint() {
|
||||
local AgentEndpointID serial oui user pass
|
||||
local opt=""
|
||||
|
||||
if ! uci -q get obuspa.localmqtt; then
|
||||
log "Remote mqtt broker configured, skip publishing endpoint"
|
||||
return 0;
|
||||
fi
|
||||
|
||||
# return if mosquitto_pub is not present
|
||||
if [ ! "$(command -v mosquitto_pub)" ]; then
|
||||
|
|
@ -251,22 +268,24 @@ publish_endpoint() {
|
|||
fi
|
||||
|
||||
config_get user localmqtt Username
|
||||
if [ -n "${user}" ]; then
|
||||
opt="-u ${user}"
|
||||
fi
|
||||
config_get pass localmqtt Password
|
||||
if [ -n "${pass}" ]; then
|
||||
opt="${opt} -P ${pass}"
|
||||
fi
|
||||
|
||||
# publish Agent's EndpointID in mosquito broker for discovery by usp-js
|
||||
# This is a work around till obuspa adds supports for mDNS discovery
|
||||
log "Publishing EndpointID ${AgentEndpointID} to local mqtt broker"
|
||||
mosquitto_pub -r -t "obuspa/EndpointID" -m "${AgentEndpointID}" ${opt}
|
||||
if [ -n "${user}" ] && [ -n "${pass}" ]; then
|
||||
log "Publishing EndpointID ${AgentEndpointID} to local mqtt broker with username, password"
|
||||
mosquitto_pub -r -t "obuspa/EndpointID" -m "${AgentEndpointID}" -u "${user}" -P "${pass}"
|
||||
elif [ -n "${user}" ]; then
|
||||
log "Publishing EndpointID ${AgentEndpointID} to local mqtt broker with username only"
|
||||
mosquitto_pub -r -t "obuspa/EndpointID" -m "${AgentEndpointID}" -u "${user}"
|
||||
else
|
||||
log "Publishing EndpointID ${AgentEndpointID} to local mqtt broker"
|
||||
mosquitto_pub -r -t "obuspa/EndpointID" -m "${AgentEndpointID}"
|
||||
fi
|
||||
}
|
||||
|
||||
configure_localagent() {
|
||||
local Enable ParameterName EndpointID
|
||||
local Enable EndpointID
|
||||
|
||||
validate_localagent_section 'localagent' || {
|
||||
log "Validation of localagent section failed"
|
||||
|
|
@ -283,7 +302,7 @@ configure_localagent() {
|
|||
configure_controller() {
|
||||
local EndpointID Enable AssignedRole PeriodicNotifInterval PeriodicNotifTime USPNotifRetryMinimumWaitInterval
|
||||
local USPNotifRetryIntervalMultiplier ControllerCode Protocol Destination coap_host coap_path coap_port
|
||||
local Reference Topic mqtt stomp assigned_role_name
|
||||
local Reference Topic mqtt stomp assigned_role_name ParameterName
|
||||
|
||||
validate_controller_section "${1}" || {
|
||||
log "Validation of controller section failed"
|
||||
|
|
@ -385,6 +404,7 @@ configure_subscription(){
|
|||
|
||||
if [ -z "${Recipient}" ] && [ -z "${controller}" ]; then
|
||||
log "No recipient for subscription"
|
||||
return 1;
|
||||
fi
|
||||
|
||||
if [ -z "${Recipient}" ]; then
|
||||
|
|
@ -407,19 +427,6 @@ configure_subscription(){
|
|||
db_set Device.LocalAgent.Subscription.${subs_num}.Recipient "${Recipient}"
|
||||
}
|
||||
|
||||
validate_challenge_section()
|
||||
{
|
||||
uci_validate_section ${CONFIGURATION} challenge "${1}" \
|
||||
'Enable:bool:true' \
|
||||
'Alias:string' \
|
||||
'Description:string' \
|
||||
'role_name:string' \
|
||||
'Role:string' \
|
||||
'Value:string' \
|
||||
'Retries:uinteger:3' \
|
||||
'LockoutPeriod:uinteger:0'
|
||||
}
|
||||
|
||||
check_json_load()
|
||||
{
|
||||
local ret=0
|
||||
|
|
@ -612,10 +619,7 @@ configure_obuspa() {
|
|||
local enabled trust_cert ifname interface debug prototrace log_level db_file log_dest role_file
|
||||
local client_cert
|
||||
|
||||
validate_obuspa_section "global" || {
|
||||
log "Validation of global section failed"
|
||||
return 1;
|
||||
}
|
||||
validate_obuspa_section "global"
|
||||
|
||||
role_def_file="${role_file}"
|
||||
|
||||
|
|
@ -685,16 +689,39 @@ configure_obuspa() {
|
|||
db_init() {
|
||||
# Load configuration
|
||||
config_load $CONFIGURATION
|
||||
config_foreach configure_obuspa obuspa
|
||||
|
||||
config_foreach configure_controller controller
|
||||
[ "$?" -ne 0 ] && return 1;
|
||||
config_foreach configure_localagent localagent
|
||||
[ "$?" -ne 0 ] && return 1;
|
||||
config_foreach configure_mtp mtp
|
||||
[ "$?" -ne 0 ] && return 1;
|
||||
config_foreach configure_stomp_connection stomp
|
||||
[ "$?" -ne 0 ] && return 1;
|
||||
config_foreach configure_mqtt_client mqtt
|
||||
[ "$?" -ne 0 ] && return 1;
|
||||
config_foreach configure_subscription subscription
|
||||
[ "$?" -ne 0 ] && return 1;
|
||||
config_foreach configure_challenges challenge
|
||||
[ "$?" -ne 0 ] && return 1;
|
||||
|
||||
db_set Internal.Reboot.Cause "LocalFactoryReset"
|
||||
return 0;
|
||||
}
|
||||
|
||||
register_service()
|
||||
{
|
||||
procd_open_instance ${CONFIGURATION}
|
||||
procd_set_param command ${PROG}
|
||||
procd_append_param command -r ${PARAM_FILE}
|
||||
|
||||
configure_obuspa
|
||||
procd_set_param respawn \
|
||||
"${respawn_threshold:-5}" \
|
||||
"${respawn_timeout:-10}" "${respawn_retry:-3}"
|
||||
|
||||
procd_set_param watch usp.raw
|
||||
procd_close_instance
|
||||
}
|
||||
|
||||
service_running() {
|
||||
|
|
@ -706,23 +733,17 @@ start_service() {
|
|||
|
||||
mkdir -p /tmp/obuspa/
|
||||
config_load obuspa
|
||||
config_get enabled global enabled
|
||||
config_get_bool enabled global enabled 0
|
||||
|
||||
if [ "${enabled}" -eq 0 ]; then
|
||||
log "OBUSPA not enabled"
|
||||
return 0;
|
||||
fi
|
||||
|
||||
procd_open_instance ${CONFIGURATION}
|
||||
procd_set_param command ${PROG}
|
||||
db_init
|
||||
procd_append_param command -r ${PARAM_FILE}
|
||||
procd_set_param respawn \
|
||||
"${respawn_threshold:-5}" \
|
||||
"${respawn_timeout:-10}" "${respawn_retry:-3}"
|
||||
[ "$?" -ne 0 ] && return 1;
|
||||
|
||||
procd_set_param watch usp.raw
|
||||
procd_close_instance
|
||||
register_service
|
||||
}
|
||||
|
||||
stop_service() {
|
||||
|
|
@ -734,7 +755,7 @@ stop_service() {
|
|||
${PROG} -c stop >/dev/null 2>&1
|
||||
|
||||
if [ -z "${db_file}" ]; then
|
||||
db_file="/tmp/usp.db"
|
||||
db_file="/tmp/obuspa/usp.db"
|
||||
fi
|
||||
|
||||
[ -f "${db_file}" ] && rm -f ${db_file}
|
||||
|
|
@ -769,4 +790,14 @@ service_triggers() {
|
|||
json_add_int "" "2000"
|
||||
json_close_array
|
||||
procd_close_trigger
|
||||
|
||||
procd_open_validate
|
||||
validate_obuspa_section
|
||||
validate_localagent_section
|
||||
validate_controller_section
|
||||
validate_subscription_section
|
||||
validate_mtp_section
|
||||
validate_stomp_connection_section
|
||||
validate_mqtt_client_section
|
||||
procd_close_validate
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue