I've been using something similar on my system and propose the following patch (first submission to the list, be gentle ;)):
diff --git a/package/base-files/files/etc/profile b/package/base-files/files/etc/profile index 0beff1608f..e8350cfd6a 100644 --- a/package/base-files/files/etc/profile +++ b/package/base-files/files/etc/profile @@ -38,3 +38,24 @@ in order to prevent unauthorized SSH logins. -------------------------------------------------- EOF fi + +service() { + if [ "$1" = "list-enabled" ]; then + for F in /etc/init.d/* ; do + $F enabled && echo "$F enabled" + done; + elif [ "$1" = "list-disabled" ]; then + for F in /etc/init.d/* ; do + $F enabled || echo "$F disabled" + done; + elif [ -f "/etc/init.d/$1" ]; then + /etc/init.d/$@ + else + echo "Usage: service list-disabled|list-enabled|<service> [command]" + if [ -n "$1" ]; then + echo "service "'"'"$1"'"'" not found, the following services are available:" + ls "/etc/init.d" + fi + return 1 + fi +} diff --git a/package/base-files/files/etc/rc.common b/package/base-files/files/etc/rc.common index 7c11544405..c44614d757 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 - enabled Check if service is started on boot + 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 "$@" +
_______________________________________________ openwrt-devel mailing list openwrt-devel@lists.openwrt.org https://lists.openwrt.org/mailman/listinfo/openwrt-devel