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
}
+ALL_HELP=""
+ALL_COMMANDS="boot shutdown depends"
+extra_command() {
+ local cmd="$1"
+ local help="$2"
+
+ local extra="$(printf "%-16s%s" "${cmd}" "${help}")"
+ ALL_HELP="${ALL_HELP}\t${extra}\n"
+ ALL_COMMANDS="${ALL_COMMANDS} ${cmd}"
+}
+
help() {
cat <<EOF
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
-$EXTRA_HELP
EOF
+ echo -e "$ALL_HELP"
}
# for procd
}
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}
+extra_command "start" "Start the service"
+extra_command "stop" "Stop the service"
+extra_command "restart" "Restart the service"
+extra_command "reload" "Reload configuration files (or restart if service does not implement reload)"
+extra_command "enable" "Enable service autostart"
+extra_command "disable" "Disable service autostart"
+extra_command "enabled" "Check if service is started on boot"
+
. "$initscript"
[ -n "$USE_PROCD" ] && {
- EXTRA_COMMANDS="${EXTRA_COMMANDS} running status trace"
- EXTRA_HELP="\
- running Check if service is running
- status Service status
-${EXTRA_HELP}"
+ 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")
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 "$@"
}
}
-ALL_COMMANDS="start stop reload restart boot shutdown enable disable enabled depends ${EXTRA_COMMANDS}"
+ALL_COMMANDS="${ALL_COMMANDS} ${EXTRA_COMMANDS}"
+ALL_HELP="${ALL_HELP}${EXTRA_HELP}"
list_contains ALL_COMMANDS "$action" || action=help
$action "$@"