procd: allow usage of * as procd_running() instance parameter

This commit is contained in:
CN_SZTL 2019-10-19 08:31:27 +08:00
parent 16f1781f0f
commit 23fbfbcf80
No known key found for this signature in database
GPG Key ID: 6850B6345C862176
2 changed files with 37 additions and 4 deletions

View File

@ -8,7 +8,7 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=procd
PKG_RELEASE:=1
PKG_RELEASE:=3
PKG_SOURCE_PROTO:=git
PKG_SOURCE_URL=$(PROJECT_GIT)/project/procd.git

View File

@ -49,6 +49,14 @@ procd_lock() {
local basescript=$(readlink "$initscript")
local service_name="$(basename ${basescript:-$initscript})"
flock -n 1000 &> /dev/null
if [ "$?" != "0" ]; then
exec 1000>"$IPKG_INSTROOT/var/lock/procd_${service_name}.lock"
flock 1000
if [ "$?" != "0" ]; then
logger "warning: procd flock for $service_name failed"
fi
fi
}
_procd_call() {
@ -399,12 +407,12 @@ _procd_add_instance() {
procd_running() {
local service="$1"
local instance="${2:-instance1}"
local running
local instance="${2:-*}"
[ "$instance" = "*" ] || instance="'$instance'"
json_init
json_add_string name "$service"
running=$(_procd_ubus_call list | jsonfilter -e "@['$service'].instances['$instance'].running")
local running=$(_procd_ubus_call list | jsonfilter -l 1 -e "@['$service'].instances[$instance].running")
[ "$running" = "true" ]
}
@ -435,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