base-files: informative service command in /etc/shinit. service command shows service...
authorStan Grishin <stangri@melmac.net>
Mon, 12 Oct 2020 22:03:15 +0000 (22:03 +0000)
committerPaul Spooren <mail@aparcar.org>
Fri, 4 Dec 2020 09:28:43 +0000 (23:28 -1000)
Usage: service <service> [command]
The following services are available:
/etc/init.d/acme                   enabled         stopped
/etc/init.d/boot                   enabled         stopped
/etc/init.d/cron                   enabled         running
/etc/init.d/dnsmasq                enabled         running
...

Signed-off-by: Stan Grishin <stangri@melmac.net>
package/base-files/Makefile
package/base-files/files/etc/shinit

index c06b534bea05ae7687dd62112457038e19cb5fb0..0c612b73ca9bdfd6aceee3747805851ece65d4cf 100644 (file)
@@ -12,7 +12,7 @@ include $(INCLUDE_DIR)/version.mk
 include $(INCLUDE_DIR)/feeds.mk
 
 PKG_NAME:=base-files
-PKG_RELEASE:=238
+PKG_RELEASE:=239
 PKG_FLAGS:=nonshared
 
 PKG_FILE_DEPENDS:=$(PLATFORM_DIR)/ $(GENERIC_PLATFORM_DIR)/base-files/
index dccba34b695d2aa80ae6318c3104ed66738ade47..8c64e81563f5694707ea99aa7435a10328d5b8a2 100644 (file)
@@ -9,12 +9,24 @@ alias ll='ls -alF --color=auto'
 [ -x /usr/bin/ldd ] || ldd() { LD_TRACE_LOADED_OBJECTS=1 $*; }
 
 service() {
-       [ -f "/etc/init.d/$1" ] || {
-               echo "service "'"'"$1"'"'" not found, the following services are available:"
-               ls "/etc/init.d"
+       if [ -f "/etc/init.d/$1" ]; then
+               /etc/init.d/$@
+       else
+               echo "Usage: service <service> [command]"
+               if [ -n "$1" ]; then
+                       echo "Service "'"'"$1"'"'" not found, the following services are available:"
+               else
+                       echo "The following services are available:"
+               fi
+               for F in /etc/init.d/* ; do
+                       printf "%-30s\t%10s\t%10s\n"  "$F" \
+                       $( $($F enabled) && echo "enabled" || echo "disabled" ) \
+                       $( [ "$(ubus call service list "{ 'verbose': true, 'name': '$(basename $F)' }" \
+                       | jsonfilter -q -e "@.$(basename $F).instances[*].running")" = "true" ] \
+                       && echo "running" || echo "stopped" )
+               done;
                return 1
-       }
-       /etc/init.d/$@
+       fi
 }
 
 [ -n "$KSH_VERSION" -o \! -s "$HOME/.shinit" ] || . "$HOME/.shinit"