mirror of
https://dev.iopsys.eu/feed/iopsys.git
synced 2026-03-08 10:17:52 +01:00
obuspa: Boot time improvements
This commit is contained in:
parent
d82756305c
commit
47396a4e4f
3 changed files with 45 additions and 47 deletions
|
|
@ -5,12 +5,12 @@
|
|||
include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_NAME:=obuspa
|
||||
PKG_VERSION:=4.1.0.12
|
||||
PKG_VERSION:=4.1.0.14
|
||||
|
||||
LOCAL_DEV:=0
|
||||
ifneq ($(LOCAL_DEV),1)
|
||||
PKG_SOURCE_PROTO:=git
|
||||
PKG_SOURCE_VERSION:=5fee30756165c275cc126509076acb716e15e1b1
|
||||
PKG_SOURCE_VERSION:=798237b65e42a8da5da2376591532ef63e07088b
|
||||
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
|
||||
|
|
@ -81,13 +81,11 @@ define Package/obuspa/install
|
|||
$(INSTALL_DIR) $(1)/etc/init.d
|
||||
$(INSTALL_DIR) $(1)/etc/config
|
||||
$(INSTALL_DIR) $(1)/etc/obuspa
|
||||
$(INSTALL_DIR) $(1)/etc/hotplug.d/iface
|
||||
$(INSTALL_BIN) $(PKG_BUILD_DIR)/obuspa $(1)/usr/sbin/
|
||||
$(INSTALL_BIN) ./files/etc/init.d/obuspa $(1)/etc/init.d/
|
||||
$(INSTALL_DATA) ./files/etc/config/obuspa $(1)/etc/config/
|
||||
$(INSTALL_DATA) ./files/etc/obuspa/roles.json $(1)/etc/obuspa/roles.json
|
||||
$(INSTALL_DATA) ./files/etc/obuspa/dmcaching_exclude.json $(1)/etc/obuspa/dmcaching_exclude.json
|
||||
$(INSTALL_BIN) ./files/etc/hotplug.d/iface/85-obuspa $(1)/etc/hotplug.d/iface/
|
||||
endef
|
||||
|
||||
$(eval $(call BuildPackage,obuspa))
|
||||
|
|
|
|||
|
|
@ -1,11 +0,0 @@
|
|||
#!/bin/sh
|
||||
|
||||
[ "$(uci -q get obuspa.global.interface)" == "$INTERFACE" ] || exit 0
|
||||
|
||||
[ "$ACTION" = ifup -o "$ACTION" = ifupdate ] || exit 0
|
||||
[ "$ACTION" = ifupdate -a -z "$IFUPDATE_ADDRESSES" ] && exit 0
|
||||
|
||||
echo "Restarting obuspa bcz ${ACTION} and ${IFUPDATE_ADDRESSES} change"|logger -t obuspa.hotplug -p debug
|
||||
|
||||
/etc/init.d/obuspa reload
|
||||
|
||||
|
|
@ -67,7 +67,7 @@ get_role_index_from_json() {
|
|||
local num=0
|
||||
|
||||
# In case of role is empty or file not present
|
||||
if [ -z "${role}" -o ! -f ${role_def_file} ]; then
|
||||
if [ -z "${role}" -o ! -f "${role_def_file}" ]; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
|
|
@ -98,7 +98,7 @@ get_role_index_from_json() {
|
|||
get_uci_ref_index() {
|
||||
local val;
|
||||
|
||||
[ -f ${USP_TEMP_FILE} ] && rm -f ${USP_TEMP_FILE}
|
||||
[ -f "${USP_TEMP_FILE}" ] && rm -f ${USP_TEMP_FILE}
|
||||
|
||||
index=0
|
||||
config_load $CONFIGURATION
|
||||
|
|
@ -167,7 +167,6 @@ validate_subscription_section()
|
|||
'Enable:bool:true' \
|
||||
'ID:string' \
|
||||
'NotifType:string' \
|
||||
'NotifRetry:bool:false' \
|
||||
'ReferenceList:string' \
|
||||
'Persistent:bool:true' \
|
||||
'Recipient:string' \
|
||||
|
|
@ -224,13 +223,30 @@ validate_mqtt_client_section()
|
|||
'ConnectRetryMaxInterval:uinteger:60'
|
||||
}
|
||||
|
||||
get_oui_from_hw() {
|
||||
local basemac="$(db get hw.board.basemac)"
|
||||
local mac="${basemac//:/}"
|
||||
|
||||
mac="${mac// /}"
|
||||
mac="$(printf "%12.12X" 0x${mac})"
|
||||
|
||||
echo "${mac:0:6}"
|
||||
}
|
||||
|
||||
get_serial_from_hw() {
|
||||
local serial="$(db get hw.board.serial_number)"
|
||||
|
||||
# this can encoded further
|
||||
echo "${serial}"
|
||||
}
|
||||
|
||||
publish_endpoint() {
|
||||
local AgentEndpointID serial oui user pass
|
||||
local opt=""
|
||||
|
||||
# return if mosquitto_pub is not present
|
||||
if ! which mosquitto_pub; then
|
||||
log "mosquitto_pub not present can't publish endpointid"
|
||||
if [ ! "$(which mosquitto_pub)" ]; then
|
||||
log "mosquitto_pub not present can't publish EndpointID"
|
||||
return 0;
|
||||
fi
|
||||
|
||||
|
|
@ -238,8 +254,8 @@ publish_endpoint() {
|
|||
config_load obuspa
|
||||
config_get AgentEndpointID localagent EndpointID ""
|
||||
if [ -z "${AgentEndpointID}" ]; then
|
||||
serial=$(ubus -t 1 call usp.raw get '{"path":"Device.DeviceInfo.SerialNumber"}'|jsonfilter -e '@["parameters"][0].value')
|
||||
oui=$(ubus -t 1 call usp.raw get '{"path":"Device.DeviceInfo.ManufacturerOUI"}'|jsonfilter -e '@["parameters"][0].value')
|
||||
serial=$(get_serial_from_hw)
|
||||
oui=$(get_oui_from_hw)
|
||||
AgentEndpointID="os::${oui}-${serial}"
|
||||
fi
|
||||
|
||||
|
|
@ -253,7 +269,7 @@ publish_endpoint() {
|
|||
fi
|
||||
|
||||
# publish Agent's EndpointID in mosquito broker for discovery by usp-js
|
||||
# This is a work around till obuspa support advertising
|
||||
# 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}
|
||||
}
|
||||
|
|
@ -293,17 +309,17 @@ configure_controller() {
|
|||
return 1;
|
||||
fi
|
||||
|
||||
if [ -z ${Reference} ]; then
|
||||
if [ ${Protocol} = "STOMP" ]; then
|
||||
if [ -z "${Reference}" ]; then
|
||||
if [ "${Protocol}" = "STOMP" ]; then
|
||||
val=$(get_uci_ref_index stomp ${stomp})
|
||||
if [ ${val} -eq 0 ]; then
|
||||
if [ "${val}" -eq 0 ]; then
|
||||
log "Not able to find the referred stomp section"
|
||||
return 1;
|
||||
fi
|
||||
Reference="Device.STOMP.Connection.${val}"
|
||||
elif [ ${Protocol} = "MQTT" ]; then
|
||||
elif [ "${Protocol}" = "MQTT" ]; then
|
||||
val=$(get_uci_ref_index mqtt ${mqtt})
|
||||
if [ ${val} -eq 0 ]; then
|
||||
if [ "${val}" -eq 0 ]; then
|
||||
log "Not able to find the referred mqtt section"
|
||||
return 1;
|
||||
fi
|
||||
|
|
@ -368,7 +384,7 @@ configure_controller() {
|
|||
}
|
||||
|
||||
configure_subscription(){
|
||||
local ID Enable NotifType NotifRetry ReferenceList Persistent Recipient
|
||||
local ID Enable NotifType ReferenceList Persistent Recipient
|
||||
local controller
|
||||
|
||||
validate_subscription_section "${1}" || {
|
||||
|
|
@ -380,9 +396,9 @@ configure_subscription(){
|
|||
log "No recipient for subscription"
|
||||
fi
|
||||
|
||||
if [ -z ${Recipient} ]; then
|
||||
if [ -z "${Recipient}" ]; then
|
||||
val=$(get_uci_ref_index controller ${controller})
|
||||
if [ ${val} -eq 0 ]; then
|
||||
if [ "${val}" -eq 0 ]; then
|
||||
log "Not able to find the referred controller section"
|
||||
return 1;
|
||||
fi
|
||||
|
|
@ -395,7 +411,6 @@ configure_subscription(){
|
|||
db_set Device.LocalAgent.Subscription.${subs_num}.Enable "${Enable}"
|
||||
db_set Device.LocalAgent.Subscription.${subs_num}.ID "${ID}"
|
||||
db_set Device.LocalAgent.Subscription.${subs_num}.NotifType "${NotifType}"
|
||||
db_set Device.LocalAgent.Subscription.${subs_num}.NotifRetry "${NotifRetry}"
|
||||
db_set Device.LocalAgent.Subscription.${subs_num}.ReferenceList "${ReferenceList}"
|
||||
db_set Device.LocalAgent.Subscription.${subs_num}.Persistent "${Persistent}"
|
||||
db_set Device.LocalAgent.Subscription.${subs_num}.Recipient "${Recipient}"
|
||||
|
|
@ -417,9 +432,9 @@ validate_challenge_section()
|
|||
check_json_load()
|
||||
{
|
||||
local ret=0
|
||||
if [ -f ${role_def_file} ]; then
|
||||
if [ -f "${role_def_file}" ]; then
|
||||
json_init
|
||||
json_load_file ${role_def_file} 2>&1 |grep -q Failed
|
||||
json_load_file "${role_def_file}" 2>&1 |grep -q Failed
|
||||
if [ $? -eq 0 ]; then # In case of invalid json file
|
||||
log "failed to load [${role_def_file}]"
|
||||
ret=1
|
||||
|
|
@ -463,7 +478,7 @@ configure_challenges() {
|
|||
exit 1;
|
||||
}
|
||||
|
||||
if [ -z "${role_name}" -a -z ${Role} ]; then
|
||||
if [ -z "${role_name}" -a -z "${Role}" ]; then
|
||||
log "Either role_name or Role must defined for a challenge";
|
||||
return 1;
|
||||
fi
|
||||
|
|
@ -499,17 +514,17 @@ configure_mtp() {
|
|||
return 1;
|
||||
}
|
||||
|
||||
if [ -z ${Reference} ]; then
|
||||
if [ ${Protocol} = "STOMP" ]; then
|
||||
if [ -z "${Reference}" ]; then
|
||||
if [ "${Protocol}" = "STOMP" ]; then
|
||||
val=$(get_uci_ref_index stomp ${stomp})
|
||||
if [ ${val} -eq 0 ]; then
|
||||
if [ "${val}" -eq 0 ]; then
|
||||
log "Referred stomp section not found"
|
||||
return 1;
|
||||
fi
|
||||
Reference="Device.STOMP.Connection.${val}"
|
||||
elif [ ${Protocol} = "MQTT" ]; then
|
||||
elif [ "${Protocol}" = "MQTT" ]; then
|
||||
val=$(get_uci_ref_index mqtt ${mqtt})
|
||||
if [ ${val} -eq 0 ]; then
|
||||
if [ "${val}" -eq 0 ]; then
|
||||
log "Referred mqtt section not found"
|
||||
return 1;
|
||||
fi
|
||||
|
|
@ -614,7 +629,7 @@ configure_obuspa() {
|
|||
|
||||
role_def_file="${role_file}"
|
||||
|
||||
if [ ${debug} -eq 1 ]; then
|
||||
if [ "${debug}" -eq 1 ]; then
|
||||
# Forward stdout of the command to logd
|
||||
procd_set_param stdout 1
|
||||
# Same for stderr
|
||||
|
|
@ -635,7 +650,6 @@ configure_obuspa() {
|
|||
|
||||
if [ -n "${interface}" ]; then
|
||||
network_get_physdev ifname ${interface}
|
||||
log "ifname from ${interface} is ${ifname}"
|
||||
fi
|
||||
|
||||
# Set this variable for root user and obuspa -c tool
|
||||
|
|
@ -691,7 +705,6 @@ db_init() {
|
|||
}
|
||||
|
||||
service_running() {
|
||||
ubus wait_for usp.raw
|
||||
publish_endpoint
|
||||
}
|
||||
|
||||
|
|
@ -706,8 +719,6 @@ start_service() {
|
|||
return 0;
|
||||
fi
|
||||
|
||||
ubus wait_for usp.raw
|
||||
|
||||
procd_open_instance ${CONFIGURATION}
|
||||
procd_set_param command ${PROG}
|
||||
db_init
|
||||
|
|
@ -732,8 +743,8 @@ stop_service() {
|
|||
db_file="/tmp/usp.db"
|
||||
fi
|
||||
|
||||
[ -f ${db_file} ] && rm -f ${db_file}
|
||||
[ -f ${PARAM_FILE} ] && rm -f ${PARAM_FILE}
|
||||
[ -f "${db_file}" ] && rm -f ${db_file}
|
||||
[ -f "${PARAM_FILE}" ] && rm -f ${PARAM_FILE}
|
||||
}
|
||||
|
||||
reload_service() {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue