procd: add procd_running() helper for checking running state
authorRafał Miłecki <rafal@milecki.pl>
Wed, 1 May 2019 05:23:21 +0000 (07:23 +0200)
committerRafał Miłecki <rafal@milecki.pl>
Thu, 2 May 2019 20:14:19 +0000 (22:14 +0200)
This should be helpful for implementing service_running() in procd init
scripts.

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
Acked-by: John Crispin <john@phrozen.org>
package/system/procd/Makefile
package/system/procd/files/procd.sh

index 2555105f1371d899440bb75e1eced5763440e5d7..03603738cd6ba70b639078a1768e62ed1aa36819 100644 (file)
@@ -8,7 +8,7 @@
 include $(TOPDIR)/rules.mk
 
 PKG_NAME:=procd
-PKG_RELEASE:=1
+PKG_RELEASE:=2
 
 PKG_SOURCE_PROTO:=git
 PKG_SOURCE_URL=$(PROJECT_GIT)/project/procd.git
index b49b2b9d0194c7aae5f63a3f82b90918218d5060..8d6d4060125f7dc8c07f967ac323793fb7b32d3e 100644 (file)
@@ -30,6 +30,9 @@
 # procd_close_instance():
 #   Complete the instance being prepared
 #
+# procd_running(service, [instance]):
+#   Checks if service/instance is currently running
+#
 # procd_kill(service, [instance]):
 #   Kill a service instance (or all instances)
 #
@@ -402,6 +405,18 @@ _procd_add_instance() {
        _procd_close_instance
 }
 
+procd_running() {
+       local service="$1"
+       local instance="${2:-instance1}"
+       local running
+
+       json_init
+       json_add_string name "$service"
+       running=$(_procd_ubus_call list | jsonfilter -e "@.$service.instances.${instance}.running")
+
+       [ "$running" = "true" ]
+}
+
 _procd_kill() {
        local service="$1"
        local instance="$2"