[OpenWrt-Devel] [PATCH] base-files: add status-ubus to init script parameters in /etc/rc.common

Stan Grishin stangri at melmac.net
Wed Jun 3 07:47:45 EDT 2020


Implement $initscript status-ubus as a short-hand for
ubus call service list "{'name': '$initscript'}"

Signed-off-by: Stan Grishin <stangri at melmac.net>
---
 package/base-files/files/etc/rc.common | 24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/package/base-files/files/etc/rc.common
b/package/base-files/files/etc/rc.common
index 7c11544405..f57895c822 100755
--- a/package/base-files/files/etc/rc.common
+++ b/package/base-files/files/etc/rc.common
@@ -67,13 +67,14 @@ help() {
 Syntax: $initscript [command]

 Available commands:
- start Start the service
- stop Stop the service
- restart Restart the service
- reload Reload configuration files (or restart if service does not
implement reload)
- enable Enable service autostart
- disable Disable service autostart
+ start Start the service
+ stop Stop the service
+ restart Restart the service
+ reload Reload configuration files (or restart if service does not
implement reload)
+ enable Enable service autostart
+ disable Disable service autostart
  enabled Check if service is started on boot
+ status-ubus Show ubus info for the service
 $EXTRA_HELP
 EOF
 }
@@ -165,6 +166,13 @@ ${EXTRA_HELP}"
  }
 }

-ALL_COMMANDS="start stop reload restart boot shutdown enable disable
enabled depends ${EXTRA_COMMANDS}"
-list_contains ALL_COMMANDS "$action" || action=help
+status_ubus() {
+ name="$(basename "${initscript}")"
+ /bin/ubus call service list "{'name': '$name'}"
+ return 0
+}
+
+ALL_COMMANDS="start stop reload restart boot shutdown enable disable
enabled depends status-ubus ${EXTRA_COMMANDS}"
+list_contains ALL_COMMANDS "$action" && action="${action/-/_}" || action=help
 $action "$@"
+
-- 
2.25.1

_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel



More information about the openwrt-devel mailing list