ubus-scriptd
來源:ubus-scriptd
ubus-scriptd主要自動帶起ubus service
因此只要停止ubus-scriptd,將會停止自動被帶起的ubus service
ubus-scriptd有下例程序:
app_load_services
由/usr/lib/ubus-services目錄加入ubus service
目前只提供使用lua寫的程式app_load_scripts
由/usr/lib/ubus目錄加入ubus service
此目前可以存放binary及script,需要依據使用方式app_load_script程序
讀取/usr/lib/ubus檔案,並且執行檔案帶參數(.methods)
此時程式需要回應ubus mehtod的json檔案,並將此method加入obj檔有人通過ubus call會將參數帶入執行檔
ex. /usr/lib/ubus cmd-json
ubus-scriptd flow
ubus-scriptd
使用fork各別帶起lua(此lua內部使用ubus.so建立)
各別執行/usr/lib/ubus,並且帶參數(.methods)來取得obj method json格式rpc_shell_script
將ubus call的參數帶給/usr/lib/ubus/xxx cmd
並將回傳值給client
ubus-scriptd
目前使用ubus source的test.lua
# ls -l /usr/lib/ubus-services/ -rwxr-xr-x 1 root root 987 Feb 9 2017 test.lua
ubus-scriptd
/opt/dvr_board/bin # ./ubus-scriptd parsing {"test":{"id":"int","msg":"string"}} _parse_methods_json: allocating 48 bytes for methods - found test - blobattr: test id int - blobattr: test msg string _parse_methods_json: method test with 2 params - 1 methods for /usr/lib/ubus/test-script Registering ubus object /test-script (-test-script)
目前提供service
/usr/lib/ubus # ubus list -v '/test-script' @19631336 "test":{"id":"Integer","msg":"String"} 'broken' @64312369 "hello1":{} 'test' @103e8e78 "hello":{"id":"Integer","msg":"String"} "hello1":{"id":"Integer","msg":"String"}
Example
ubus-scriptd
目前提供service
Call to function 'hello' key=id value=123 key=msg value=tt123 Call to test event key=id value=123 key=msg value=send test
ubus call
test-script直接回應帶入參數
/usr/lib/ubus # ubus call /test-script test '{"id":123,"msg":"str123"}' { "id": 123, "msg": "str123" }
ubus call
test.lua的hello
/usr/lib/ubus # ubus call test hello '{"id":123,"msg":"tt123"}' { "message": "foo" }
ubus send
ubus send test '{"id":123,"msg":"send test"}
JUCI
github : juci
JUCI JavaScript Webgui for embedded devices running OpenWRT
JUCI scripts and services are handled entirely by a small C program called ubus-scriptd
it creates ubus objects for all the scripts that are published into /usr/lib/ubus/ directory tree
creates a ubus object and then listens for incoming ubus calls
Writing a ubus script
Writing a ubus service
Services are different from scripts in that they register their own ubus methods directly and always maintain a running instance of the service in the background
/usr/lib/ubus-services/
All ubus-scriptd services are written in lua