procd: move service command to procd
[openwrt/staging/dedeckeh.git] / package / system / procd / files / service
1 #!/bin/sh
2
3 main() {
4 local service="$1"
5 local cmd="$2"
6
7 local boot status
8
9 if [ -f "/etc/init.d/${service}" ]; then
10 /etc/init.d/"${service}" "${cmd}"
11 exit "$?"
12 fi
13
14 if [ -n "$service" ]; then
15 echo "Service \"$1\" 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 "$@"