Nick
October 28, 2022, 10:39am
1
Hi LUCI author:
I tried to use luci-app-example to add a new page with my LUCI21.02.
I want to trigger a back-end script execution after I click "Save&Apply" in "Example/Form View" page.
I composed a script named "example" which located in /etc/init.d/ like this:
#!/bin/sh /etc/rc.common
START=20
STOP=90
USE_PROCD=1
start_service() {
echo "start service example" >> "/var/run/log"
}
reload_service() {
echo "reload service example" >> "/var/run/log"
}
stop_service() {
echo "stop service example" >> "/var/run/log"
}
And I also add a code piece to /etc/config/ucitrack like this:
config example
option init example
The luci-app-example.json is like this:
{
"luci-app-example": {
"description": "Grant UCI access to LuCI app ecample",
"read": {
"cgi-io": [ "exec" ],
"ubus": {
"file": [ "exec" ],
"uci": [ "changes", "get" ]
},
"uci": [
"example"
]
},
"write": {
"cgi-io": [ "exec" ],
"ubus": {
"file": [ "exec" ],
"uci": [ "add", "apply", "confirm", "delete", "order", "rename", "set" ]
},
"uci": [
"example"
]
}
}
}
But after I click the "Save&Apply" at Example/Form View page, nothing happlen(No /var/run/log exist, it's look like my /etc/init.d/example never been executed at all.
Can you tell me why?
Besides, since there is no any document about how to compose the menu.d/XX.json and acl.d/XX.json, It's really hard for me to proceed with my development, sincerely hope you can write a guideline about this.
jow
October 28, 2022, 1:52pm
2
In your init script, add:
service_triggers() {
procd_add_reload_trigger example
}
This will execute an /etc/init.d/example reload
when LuCI commits /etc/config/example
.
As for the JSON menu items, you can find some info here:
/usr/share/acl.d belongs to ubusd and was introduced later, it is unrelated to LuCI and can be ignored (the defaults are sufficient for LuCI to operate)
/usr/share/rpcd/acl.d/ controls rpcd's ACL mechanism. Details here: https://openwrt.org/docs/techref/ubus#acls
/usr/share/luci/menu.d/ is a directory of JSON files describing the LuCI menu nodes.
Name and order of files does not matter
Contents from all files are merged into one common tree.
Possible fields here: https://github.com/openwrt…
See also the post below for a general overview over the request routing flow:
In general the request routing flow is:
uhttpd (or another web server) invokes /www/cgi-bin/luci, passes request info via env vars & stdin (basic CGI interface)
/www/cgi-bin/luci instantiates the luci.sgi.cgi class (sgi = Server Gateway Interface, a module to translate the server specific env to a common LuCI-internal HTTP request state) and invokes its run() method. There might be others but not relevant for the basic logic flow
luci.sgi.cgi builds an HTTP request object from the provided i…
1 Like
Nick
October 31, 2022, 11:33am
3
Hi Jow
Thanks for your reply.
service_triggers() {
procd_add_reload_trigger example
}
After I tried this patch, unfortunately it did not work(I mean click Save&Apply from web page).
I also tried to use uci command line, but did not work as well.
root@OpenWrt:/etc/init.d#uci set example.first.first_option=99
root@OpenWrt:/etc/init.d#uci commit
Are you sure that "uci commit" would trigger the /etc/init.d/XXX script execution?
jow
October 31, 2022, 12:53pm
4
A uci commit
on the cli does not trigger the reload mechanism (you can invoke /sbin/reload_config
after uci commit
for that).
A uci commit call via ubus (as used by LuCI) should trigger the reload though.
Example:
root@er-x:~# vi /etc/init.d/example
root@er-x:~# cat /etc/init.d/example
#!/bin/sh /etc/rc.common
START=20
STOP=90
USE_PROCD=1
start_service() {
echo "start service example" >> "/var/run/log"
}
reload_service() {
echo "reload service example" >> "/var/run/log"
}
stop_service() {
echo "stop service example" >> "/var/run/log"
}
service_triggers() {
procd_add_reload_trigger example
}
root@er-x:~# chmod +x /etc/init.d/example
root@er-x:~# /etc/init.d/example enable
root@er-x:~# touch /etc/config/example
root@er-x:~# uci add example example
cfg0199f1
root@er-x:~# uci set example.@example[-1].foo=bar
root@er-x:~# uci commit example
root@er-x:~# /etc/init.d/example start
root@er-x:~# cat /var/run/log
start service example
root@er-x:~# ubus call uci set '{ "config": "example", "section": "@example[-1]", "values": { "foo": "baz" } }'
root@er-x:~# cat /var/run/log
start service example
root@er-x:~# ubus call uci commit '{ "config": "example" }'
root@er-x:~# cat /var/run/log
start service example
reload service example
root@er-x:~#
system
Closed
November 13, 2022, 2:32am
6
This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.