aboutsummaryrefslogtreecommitdiffstats
path: root/package/system
diff options
context:
space:
mode:
authorLuiz Angelo Daros de Luca <luizluca@gmail.com>2018-09-11 22:35:09 -0300
committerPetr Štetiar <ynezz@true.cz>2019-09-15 22:53:01 +0200
commit7519a36774ca0e50dfae6a4b9fea75cab95171a5 (patch)
treecad59cdd370e0c6d04013cb92d2d45c0a22b7757 /package/system
parented5b9129d7a47adaecdce694cec8e7b61131a9da (diff)
downloadupstream-7519a36774ca0e50dfae6a4b9fea75cab95171a5.tar.gz
upstream-7519a36774ca0e50dfae6a4b9fea75cab95171a5.tar.bz2
upstream-7519a36774ca0e50dfae6a4b9fea75cab95171a5.zip
base-files,procd: add generic service status
Adds a default status action for init.d scripts. procd "service status" will return: 0) for loaded services (even if disabled by conf or dead) 3) for inactive services 4) when filtering a non-existing instance Signed-off-by: Luiz Angelo Daros de Luca <luizluca@gmail.com> [rebased, cleaned up] Signed-off-by: Petr Štetiar <ynezz@true.cz>
Diffstat (limited to 'package/system')
-rw-r--r--package/system/procd/files/procd.sh25
1 files changed, 25 insertions, 0 deletions
diff --git a/package/system/procd/files/procd.sh b/package/system/procd/files/procd.sh
index 8d6d406012..a9d2b341be 100644
--- a/package/system/procd/files/procd.sh
+++ b/package/system/procd/files/procd.sh
@@ -443,6 +443,31 @@ _procd_send_signal() {
_procd_ubus_call signal
}
+_procd_status() {
+ local service="$1"
+ local instance="$2"
+ local data
+
+ json_init
+ [ -n "$service" ] && json_add_string name "$service"
+
+ data=$(_procd_ubus_call list | jsonfilter -e '@["'"$service"'"]')
+ [ -z "$data" ] && { echo "inactive"; return 3; }
+
+ data=$(echo "$data" | jsonfilter -e '$.instances')
+ if [ -z "$data" ]; then
+ [ -z "$instance" ] && { echo "active with no instances"; return 0; }
+ data="[]"
+ fi
+
+ [ -n "$instance" ] && instance="\"$instance\"" || instance='*'
+ if [ -z "$(echo "$data" | jsonfilter -e '$['"$instance"']')" ]; then
+ echo "unknown instance $instance"; return 4
+ else
+ echo "running"; return 0
+ fi
+}
+
procd_open_data() {
local name="$1"
json_set_namespace procd __procd_old_cb