# file: configuration files (array)
# netdev: bound network device (detects ifindex changes)
# limits: resource limits (passed to the process)
-# user info: array with 1 values $username
+# user: $username to run service as
+# group: $groupname to run service as
# pidfile: file name to write pid into
+# stdout: boolean whether to redirect commands stdout to syslog (default: 0)
+# stderr: boolean whether to redirect commands stderr to syslog (default: 0)
+# facility: syslog facility used when logging to syslog (default: daemon)
#
# No space separation is done for arrays/tables - use one function argument per command line argument
#
# 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)
#
reload_signal)
json_add_int "$type" $(kill -l "$1")
;;
- pidfile|user|seccomp|capabilities)
+ pidfile|user|group|seccomp|capabilities|facility)
json_add_string "$type" "$1"
;;
stdout|stderr|no_new_privs)
_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"
_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