sulu: generate dm cache

This commit is contained in:
Vivek Kumar Dutta 2025-09-12 16:44:27 +05:30 committed by Vivek Dutta
parent e451e32f77
commit d939c3fe6d
5 changed files with 134 additions and 0 deletions

View file

@ -100,15 +100,20 @@ define Package/sulu/install/Default
$(INSTALL_BIN) ./files/etc/sulu/sulu.sh $(1)/etc/sulu/
$(INSTALL_DATA) ./files/etc/sulu/nginx.locations $(1)/etc/sulu/
$(INSTALL_BIN) ./files/etc/sulu/sulu_cache.sh $(1)/etc/sulu/
$(INSTALL_BIN) ./files/etc/sulu/cache_dm.js $(1)/etc/sulu/
$(INSTALL_DIR) $(1)/etc/users/roles
$(INSTALL_DATA) ./files/etc/users/roles/*.json $(1)/etc/users/roles/
$(INSTALL_DIR) $(1)/etc/uci-defaults
$(INSTALL_DATA) ./files/etc/uci-defaults/39-sulu-cache-config $(1)/etc/uci-defaults/
$(INSTALL_DATA) ./files/etc/uci-defaults/40-add-sulu-config $(1)/etc/uci-defaults/
ifneq ($(CONFIG_SULU_DEFAULT_UI)$(CONFIG_SULU_BUILDER_DEFAULT_UI),)
$(INSTALL_DATA) ./files/etc/uci-defaults/41-make-sulu-default-ui $(1)/etc/uci-defaults/
endif
$(INSTALL_DIR) $(1)/etc/init.d
$(INSTALL_BIN) ./files/etc/init.d/sulu $(1)/etc/init.d/
endef
define Package/sulu/install/Post

View file

@ -0,0 +1,19 @@
#!/bin/sh /etc/rc.common
START=9
STOP=01
USE_PROCD=1
PROG=/etc/sulu/sulu_cache.sh
log() {
echo "${@}"|logger -t sulu.init -p info
}
start_service()
{
procd_open_instance "sulu"
procd_set_param command ${PROG}
procd_close_instance "sulu"
}

View file

@ -0,0 +1,36 @@
#!/usr/bin/env qjs
import * as std from 'std';
import connect from "/usr/lib/usp-js/index.js";
const run = async () => {
try {
const usp = await connect({
host: "127.0.0.1",
port: 9004,
protocol: "ws",
username: USER,
fromId: "self::sulu-" + USER,
publishEndpoint: "/usp/" + ID + "/" + USER + "/endpoint",
subscribeEndpoint: "/usp/" + ID + "/" + USER + "/controller",
toId: "os::" + ID
});
const result = await usp.getNested("Device.")
print(JSON.stringify(result, null, 0))
await usp.disconnect();
} catch(err) {
print("ERROR")
std.exit(2)
}
};
if (scriptArgs.length < 3 ) {
print("Invalid Syntax")
std.exit(1)
}
const USER = scriptArgs[1]
const ID = scriptArgs[2]
run();

View file

@ -0,0 +1,54 @@
#!/bin/sh
if ! command -v obuspa >/dev/null 2>&1; then
exit 0
fi
if [ ! -f "/etc/config/userinterface" ]; then
exit 0
fi
ENDPOINTID=""
SULU_PATH="/sulu/presets"
USERS="$(uci -q get userinterface._sulu_s.role)"
log() {
logger -t sulu_cache "$*"
echo "# $* #" >/dev/console
}
wait_for_obuspa() {
while true; do
ENDPOINTID="$(obuspa -c get Device.LocalAgent.EndpointID |grep Device.|awk '{print $3}')"
sleep 1
if [ -n "${ENDPOINTID}" ]; then
log "OBUSPA running endpointid [${ENDPOINTID}]"
break;
fi
done
}
generate_sulu_dm_cache() {
local ID user
ID="${ENDPOINTID//os::/}"
for user in $USERS; do
count=0
while [ "${count}" -lt "5" ]; do
if [ -n "${user}" ] && [ -n "${ID}" ]; then
qjs /etc/sulu/cache_dm.js $user $ID > /tmp/dm_${user}.json
if cat /tmp/dm_${user}.json| jsonfilter -e '@' >/dev/null 2>&1; then
mv /tmp/dm_${user}.json ${SULU_PATH}/dm_${user}.json
break
else
log "Failed[${count}] generating caching [${user}], [${ID}]"
count="$(( count + 1 ))"
sleep 1
fi
fi
done
done
}
wait_for_obuspa
generate_sulu_dm_cache

View file

@ -0,0 +1,20 @@
#!/bin/sh
if [ ! -f "/etc/config/mosquitto" ]; then
echo "Local mosquitto broker not available"
return 0
fi
add_sulu_cache_config_to_mosquitto()
{
if ! uci_get mosquitto sulu_cache >/dev/null 2>&1; then
uci_add mosquitto listener sulu_cache
uci_set mosquitto sulu_cache enabled 1
uci_set mosquitto sulu_cache port '9004'
uci_set mosquitto sulu_cache protocol 'websockets'
uci_set mosquitto sulu_cache no_remote_access '1'
uci_set mosquitto sulu_cache allow_anonymous '1'
fi
}
add_sulu_cache_config_to_mosquitto