diff mbox series

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

Message ID CALu2O0QqhNN7kr5ntuazybt0qYz1aFpWoO+9xj2EzJssDYtJoQ@mail.gmail.com
State New
Headers show
Series [OpenWrt-Devel] base-files: add status-ubus to init script parameters in /etc/rc.common | expand

Commit Message

Stan Grishin June 3, 2020, 11:47 a.m. UTC
Implement $initscript status-ubus as a short-hand for
ubus call service list "{'name': '$initscript'}"

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

 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 "$@"
+
diff mbox series

Patch

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