Documentation on creating ubus service

I'd like my app to provide a ubus service so users could use the ubus system to monitor it and/or send it commands. I cam't find any documentation on how to add a ubus service, does any documentation exist?

There is some example code available at https://git.openwrt.org/?p=project/ubus.git;a=tree;f=examples;h=0a40493e27f2210a9213ea2aad3df920d77666d4;hb=d35df8adda873dc75d876f72b78e84db8cfa72ee

Thanks @jow I have that code but I'm not a fan of blindly copying code without having a good understanding of the design intent.

did you end up finding any more documentation?

@chrisvincent Alas no I did not so I ended up following the example code @jow provided and was able to successfully create my service.

I think one point that should be added is that you may not need to create a service, instead, you can use configuration to achieve similar results if you simply need to use existing binaries. The sample below provides a UBUS service named "cw" that can be used to call opkg and passes the list or update command.

#!/bin/sh

This file lives in /usr/libexec/rpcd

adds opkg upgrade function to UBUS

case "$1" in
list)
echo '{ "update": { } }'
;;
call)
case "$2" in
update)
# read the arguments
# read input;

                            # optionally log the call
                            logger -t "cw" "call" "$2"

                            # return json object or an array
                            ret=$(opkg update)
                            ret2=$(opkg upgrade <my app name>) 
                            echo '{"status":"OK", "Msg1":"'"$ret"'", "Msg2":"'"$ret2"'" }'
                    ;;
            esac
    ;;

esac

1 Like

thanks @crispyoz

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.