base-files: add wrapper for procd service list command
[openwrt/staging/wigyori.git] / package / base-files / files / etc / rc.common
index d3d91ef2509192c5c5acaa73ef05b48857bf6534..d7473038444cb1b6b4f58f408e3cbd2bfdd94f4b 100755 (executable)
@@ -55,22 +55,27 @@ enable() {
 
 enabled() {
        name="$(basename "${initscript}")"
-       [ -x "$IPKG_INSTROOT/etc/rc.d/S${START}${name##S[0-9][0-9]}" ]
+       name="${name##[SK][0-9][0-9]}"
+       {
+               [ -z "${START:-}" ] || [ -L "$IPKG_INSTROOT/etc/rc.d/S${START}$name" ]
+       } && {
+               [ -z "${STOP:-}" ] || [ -L "$IPKG_INSTROOT/etc/rc.d/K${STOP}$name" ]
+       }
 }
 
 depends() {
        return 0
 }
 
-EXTRA_HELP=""
-EXTRA_COMMANDS="boot shutdown depends"
+ALL_HELP=""
+ALL_COMMANDS="boot shutdown depends"
 extra_command() {
        local cmd="$1"
        local help="$2"
 
        local extra="$(printf "%-16s%s" "${cmd}" "${help}")"
-       EXTRA_HELP="${EXTRA_HELP}\t${extra}\n"
-       EXTRA_COMMANDS="${EXTRA_COMMANDS} ${cmd}"
+       ALL_HELP="${ALL_HELP}\t${extra}\n"
+       ALL_COMMANDS="${ALL_COMMANDS} ${cmd}"
 }
 
 help() {
@@ -79,7 +84,7 @@ Syntax: $initscript [command]
 
 Available commands:
 EOF
-       echo -e "$EXTRA_HELP"
+       echo -e "$ALL_HELP"
 }
 
 # for procd
@@ -100,9 +105,9 @@ service_data() {
 }
 
 service_running() {
-       local service="${1:-$(basename $initscript)}"
-       local instance="${2:-*}"
-       procd_running "$service" "$instance" "$@"
+       local instance="${1:-*}"
+
+       procd_running "$(basename $initscript)" "$instance"
 }
 
 ${INIT_TRACE:+set -x}
@@ -121,6 +126,7 @@ extra_command "enabled" "Check if service is started on boot"
        extra_command "running" "Check if service is running"
        extra_command "status" "Service status"
        extra_command "trace" "Start with syscall trace"
+       extra_command "info" "Dump procd service info"
 
        . $IPKG_INSTROOT/lib/functions/procd.sh
        basescript=$(readlink "$initscript")
@@ -144,6 +150,13 @@ extra_command "enabled" "Check if service is started on boot"
                start "$@"
        }
 
+       info() {
+               json_init
+               json_add_string name "$(basename ${basescript:-$initscript})"
+               json_add_boolean verbose "1"
+               _procd_ubus_call list
+       }
+
        stop() {
                procd_lock
                stop_service "$@"
@@ -175,6 +188,7 @@ extra_command "enabled" "Check if service is started on boot"
        }
 }
 
-ALL_COMMANDS="${EXTRA_COMMANDS}"
+ALL_COMMANDS="${ALL_COMMANDS} ${EXTRA_COMMANDS}"
+ALL_HELP="${ALL_HELP}${EXTRA_HELP}"
 list_contains ALL_COMMANDS "$action" || action=help
 $action "$@"