luci-base: use json for ucitrack instead of uci
authorFlorian Eckert <fe@dev.tdt.de>
Wed, 10 Apr 2024 15:23:06 +0000 (17:23 +0200)
committerFlorian Eckert <fe@dev.tdt.de>
Thu, 11 Apr 2024 13:49:44 +0000 (15:49 +0200)
The 'ucitrack' configuration under '/etc/config' defines which service must
be restarted on a LuCI change. This uci file defines how all this works
together. Additionally there are 'uci-defaults' scripts in the various
applications that add additional configurations parameters to this ucitrack
file if a service must be reloaded/restarted on a LuCI change.

There are some problems with the current implementation:

* The uci should be used to configure the system and not for this kind of
  reload/restart dependency handling on LuCI changes.
* On a system update with configuration restore of the 'ucitrack' file
  the new behavior on LuCI reload/restart could not take into account
  because the new file is *not* used.

This commit converts the handling from uci to json.

Signed-off-by: Florian Eckert <fe@dev.tdt.de>
19 files changed:
modules/luci-base/Makefile
modules/luci-base/root/etc/config/ucitrack [deleted file]
modules/luci-base/root/etc/init.d/ucitrack
modules/luci-base/root/usr/share/ucitrack/dhcp.json [new file with mode: 0644]
modules/luci-base/root/usr/share/ucitrack/dropbear.json [new file with mode: 0644]
modules/luci-base/root/usr/share/ucitrack/firewall.json [new file with mode: 0644]
modules/luci-base/root/usr/share/ucitrack/fstab.json [new file with mode: 0644]
modules/luci-base/root/usr/share/ucitrack/httpd.json [new file with mode: 0644]
modules/luci-base/root/usr/share/ucitrack/luci_splash.json [new file with mode: 0644]
modules/luci-base/root/usr/share/ucitrack/network.json [new file with mode: 0644]
modules/luci-base/root/usr/share/ucitrack/ntpclient.json [new file with mode: 0644]
modules/luci-base/root/usr/share/ucitrack/odhcpd.json [new file with mode: 0644]
modules/luci-base/root/usr/share/ucitrack/olsr.json [new file with mode: 0644]
modules/luci-base/root/usr/share/ucitrack/qos.json [new file with mode: 0644]
modules/luci-base/root/usr/share/ucitrack/samba.json [new file with mode: 0644]
modules/luci-base/root/usr/share/ucitrack/system.json [new file with mode: 0644]
modules/luci-base/root/usr/share/ucitrack/tinyproxy.json [new file with mode: 0644]
modules/luci-base/root/usr/share/ucitrack/upnpd.json [new file with mode: 0644]
modules/luci-base/root/usr/share/ucitrack/wireless.json [new file with mode: 0644]

index 6913568948aefbadb53c39571944d9fe1a02159f..789e6a4bf6fa2c5846e8e36b754cfc4f3e4fb588 100644 (file)
@@ -36,7 +36,6 @@ include $(INCLUDE_DIR)/host-build.mk
 define Package/luci-base/conffiles
 /etc/luci-uploads
 /etc/config/luci
-/etc/config/ucitrack
 endef
 
 define Package/luci-base/postinst
diff --git a/modules/luci-base/root/etc/config/ucitrack b/modules/luci-base/root/etc/config/ucitrack
deleted file mode 100644 (file)
index bb4cdbc..0000000
+++ /dev/null
@@ -1,56 +0,0 @@
-config network
-       option init network
-       list affects dhcp
-
-config wireless
-       list affects network
-
-config firewall
-       option init firewall
-       list affects luci-splash
-       list affects qos
-       list affects miniupnpd
-
-config olsr
-       option init olsrd
-
-config dhcp
-       option init dnsmasq
-       list affects odhcpd
-
-config odhcpd
-       option init odhcpd
-
-config dropbear
-       option init dropbear
-
-config httpd
-       option init httpd
-
-config fstab
-       option exec '/sbin/block mount'
-
-config qos
-       option init qos
-
-config system
-       option init led
-       option exec '/etc/init.d/log reload'
-       list affects luci_statistics
-       list affects dhcp
-
-config luci_splash
-       option init luci_splash
-
-config upnpd
-       option init miniupnpd
-
-config ntpclient
-       option init ntpclient
-
-config samba
-       option init samba
-
-config tinyproxy
-       option init tinyproxy
-
index 57ac11857f5aa6be71a5f90da4cfe80cebf024ca..495949f64fbcd4ebf284f2e92eb9e34bf84421f5 100755 (executable)
@@ -3,6 +3,8 @@
 START=80
 USE_PROCD=1
 
+. "$IPKG_INSTROOT/usr/share/libubox/jshn.sh"
+
 register_init() {
        local config="$1"
        local init="$2"
@@ -15,13 +17,25 @@ register_init() {
 }
 
 register_trigger() {
-       local sid="$1"
+       local uci="$1"
+       local file="$2"
+
        local config init exec affects affected
+       local prev
 
-       config_get config "$sid" TYPE
-       config_get init "$sid" init
-       config_get exec "$sid" exec
-       config_get affects "$sid" affects
+       json_set_namespace config prev
+       json_init
+       json_load_file "${file}" >/dev/null 2>&1
+       json_get_var config 'config'
+       [ "$config" = "$uci" ] || {
+               json_set_namespace "$prev"
+               return
+       }
+       json_get_var init 'init'
+       json_get_var exec 'exec'
+       json_get_values affects 'affects'
+       json_cleanup
+       json_set_namespace "$prev"
 
        if [ -n "$init" ]; then
                register_init "$config" "/etc/init.d/$init" "reload"
@@ -48,10 +62,19 @@ register_trigger() {
        done
 }
 
-service_triggers() {
-       config_foreach register_trigger
+check_trigger() {
+       local config="$1"
+
+       local file
+
+       for file in /usr/share/ucitrack/*.json; do
+               [ -f "$file" ] || continue
+               register_trigger "$config" "$file"
+       done
 }
 
-start_service() {
-       config_load ucitrack
+service_triggers() {
+       for config in /etc/config/*; do
+               check_trigger "${config##*/}"
+       done
 }
diff --git a/modules/luci-base/root/usr/share/ucitrack/dhcp.json b/modules/luci-base/root/usr/share/ucitrack/dhcp.json
new file mode 100644 (file)
index 0000000..260ee3d
--- /dev/null
@@ -0,0 +1,7 @@
+{
+       "config": "dhcp",
+       "init": "dnsmasq",
+       "affects": [
+               "odhcpd"
+       ]
+}
diff --git a/modules/luci-base/root/usr/share/ucitrack/dropbear.json b/modules/luci-base/root/usr/share/ucitrack/dropbear.json
new file mode 100644 (file)
index 0000000..fc24cd9
--- /dev/null
@@ -0,0 +1,4 @@
+{
+       "config": "dropbear",
+       "init": "dropbear"
+}
diff --git a/modules/luci-base/root/usr/share/ucitrack/firewall.json b/modules/luci-base/root/usr/share/ucitrack/firewall.json
new file mode 100644 (file)
index 0000000..4d1d9f9
--- /dev/null
@@ -0,0 +1,9 @@
+{
+       "config": "firewall",
+       "init": "firewall",
+       "affects": [
+               "luci-splash",
+               "qos",
+               "miniupnpd"
+       ]
+}
diff --git a/modules/luci-base/root/usr/share/ucitrack/fstab.json b/modules/luci-base/root/usr/share/ucitrack/fstab.json
new file mode 100644 (file)
index 0000000..95b0711
--- /dev/null
@@ -0,0 +1,4 @@
+{
+       "config": "fstab",
+       "exec": "/sbin/block mount"
+}
diff --git a/modules/luci-base/root/usr/share/ucitrack/httpd.json b/modules/luci-base/root/usr/share/ucitrack/httpd.json
new file mode 100644 (file)
index 0000000..ae549b6
--- /dev/null
@@ -0,0 +1,4 @@
+{
+       "config": "httpd",
+       "init": "httpd"
+}
diff --git a/modules/luci-base/root/usr/share/ucitrack/luci_splash.json b/modules/luci-base/root/usr/share/ucitrack/luci_splash.json
new file mode 100644 (file)
index 0000000..0d1ffe1
--- /dev/null
@@ -0,0 +1,4 @@
+{
+       "config": "luci_splash",
+       "init": "luci_splash"
+}
diff --git a/modules/luci-base/root/usr/share/ucitrack/network.json b/modules/luci-base/root/usr/share/ucitrack/network.json
new file mode 100644 (file)
index 0000000..99d31fc
--- /dev/null
@@ -0,0 +1,7 @@
+{
+       "config": "network",
+       "init": "network",
+       "affects": [
+               "dhcp"
+       ]
+}
diff --git a/modules/luci-base/root/usr/share/ucitrack/ntpclient.json b/modules/luci-base/root/usr/share/ucitrack/ntpclient.json
new file mode 100644 (file)
index 0000000..629d321
--- /dev/null
@@ -0,0 +1,4 @@
+{
+       "config": "ntpclient",
+       "init": "ntpclient"
+}
diff --git a/modules/luci-base/root/usr/share/ucitrack/odhcpd.json b/modules/luci-base/root/usr/share/ucitrack/odhcpd.json
new file mode 100644 (file)
index 0000000..2c78e1e
--- /dev/null
@@ -0,0 +1,4 @@
+{
+       "config": "odhcpd",
+       "init": "odhcpd"
+}
diff --git a/modules/luci-base/root/usr/share/ucitrack/olsr.json b/modules/luci-base/root/usr/share/ucitrack/olsr.json
new file mode 100644 (file)
index 0000000..54f792a
--- /dev/null
@@ -0,0 +1,4 @@
+{
+       "config": "olsr",
+       "init": "olsrd"
+}
diff --git a/modules/luci-base/root/usr/share/ucitrack/qos.json b/modules/luci-base/root/usr/share/ucitrack/qos.json
new file mode 100644 (file)
index 0000000..27b50d5
--- /dev/null
@@ -0,0 +1,4 @@
+{
+       "config": "qos",
+       "init": "qos"
+}
diff --git a/modules/luci-base/root/usr/share/ucitrack/samba.json b/modules/luci-base/root/usr/share/ucitrack/samba.json
new file mode 100644 (file)
index 0000000..b50a8dd
--- /dev/null
@@ -0,0 +1,4 @@
+{
+       "config": "samba",
+       "init": "samba"
+}
diff --git a/modules/luci-base/root/usr/share/ucitrack/system.json b/modules/luci-base/root/usr/share/ucitrack/system.json
new file mode 100644 (file)
index 0000000..f3da5ce
--- /dev/null
@@ -0,0 +1,9 @@
+{
+       "config": "system",
+       "init": "led",
+       "exec": "/etc/init.d/log reload",
+       "affects": [
+               "luci_statistics",
+               "dhcp"
+       ]
+}
diff --git a/modules/luci-base/root/usr/share/ucitrack/tinyproxy.json b/modules/luci-base/root/usr/share/ucitrack/tinyproxy.json
new file mode 100644 (file)
index 0000000..252144f
--- /dev/null
@@ -0,0 +1,4 @@
+{
+       "config": "tinyproxy",
+       "init": "tinyproxy"
+}
diff --git a/modules/luci-base/root/usr/share/ucitrack/upnpd.json b/modules/luci-base/root/usr/share/ucitrack/upnpd.json
new file mode 100644 (file)
index 0000000..a9e1902
--- /dev/null
@@ -0,0 +1,4 @@
+{
+       "config": "upnpd",
+       "init": "miniupnpd"
+}
diff --git a/modules/luci-base/root/usr/share/ucitrack/wireless.json b/modules/luci-base/root/usr/share/ucitrack/wireless.json
new file mode 100644 (file)
index 0000000..edbaee7
--- /dev/null
@@ -0,0 +1,6 @@
+{
+       "config": "wireless",
+       "affects": [
+               "network"
+       ]
+}