b.liu | e958203 | 2025-04-17 19:18:16 +0800 | [diff] [blame^] | 1 | #!/bin/sh |
| 2 | |
| 3 | main() { |
| 4 | local service="$1" |
| 5 | shift |
| 6 | |
| 7 | local boot status |
| 8 | |
| 9 | if [ -f "/etc/init.d/${service}" ]; then |
| 10 | /etc/init.d/"${service}" "$@" |
| 11 | exit "$?" |
| 12 | fi |
| 13 | |
| 14 | if [ -n "$service" ]; then |
| 15 | echo "Service \"$service\" not found:" |
| 16 | exit 1 |
| 17 | fi |
| 18 | |
| 19 | echo "Usage: $(basename "$0") <service> [command]" |
| 20 | for service in /etc/init.d/* ; do |
| 21 | boot="$($service enabled && echo "enabled" || echo "disabled" )" |
| 22 | status="$( [ "$(ubus call service list "{ 'verbose': true, 'name': '$(basename "$service")' }" \ |
| 23 | | jsonfilter -q -e "@['$(basename "$service")'].instances[*].running" | uniq)" = "true" ] \ |
| 24 | && echo "running" || echo "stopped" )" |
| 25 | |
| 26 | printf "%-30s\\t%10s\\t%10s\\n" "$service" "$boot" "$status" |
| 27 | done |
| 28 | } |
| 29 | |
| 30 | main "$@" |