3 # procd_open_service(name, [script]):
4 # Initialize a new procd command message containing a service with one or more instances
6 # procd_close_service()
7 # Send the command message for the service
9 # procd_open_instance([name]):
10 # Add an instance to the service described by the previous procd_open_service call
12 # procd_set_param(type, [value...])
14 # command: command line (array).
15 # env: environment variable (passed to the process)
16 # data: arbitrary name/value pairs for detecting config changes (table)
17 # file: configuration files (array)
18 # netdev: bound network device (detects ifindex changes)
20 # No space separation is done for arrays/tables - use one function argument per command line argument
22 # procd_close_instance():
23 # Complete the instance being prepared
25 # procd_kill(service, [instance]):
26 # Kill a service instance (or all instances)
29 .
$IPKG_INSTROOT/usr
/share
/libubox
/jshn.sh
36 json_set_namespace procd old_cb
38 json_set_namespace
$old_cb
43 eval "$1() { _procd_call _$1 \"\$@\"; }"
51 ubus call service
"$cmd" "$(json_dump)"
55 _procd_open_service
() {
59 _PROCD_SERVICE
="$name"
63 json_add_string name
"$name"
64 [ -n "$script" ] && json_add_string
script "$script"
65 json_add_object instances
68 _procd_close_service
() {
76 _procd_add_array_data
() {
78 json_add_string
"" "$1"
86 _procd_add_array_data
"$@"
90 _procd_add_table_data
() {
94 [[ "$1" == "$val" ]] && val
=
95 json_add_string
"$var" "$val"
103 _procd_add_table_data
"$@"
107 _procd_open_instance
() {
108 local name
="$1"; shift
110 _PROCD_INSTANCE_SEQ
="$(($_PROCD_INSTANCE_SEQ + 1))"
111 name
="${name:-instance$_PROCD_INSTANCE_SEQ}"
112 json_add_object
"$name"
115 _procd_open_trigger
() {
116 json_add_array
"triggers"
120 local type="$1"; shift
124 _procd_add_table
"$type" "$@"
127 _procd_add_array
"$type" "$@"
130 json_add_int
"$type" "$1"
135 _procd_add_config_trigger
() {
137 _procd_add_array_data
"config.change"
140 _procd_add_array_data
"if"
143 _procd_add_array_data
"eq" "package" "$1"
148 _procd_add_array_data
"run_script" "$@"
156 _procd_append_param
() {
157 local type="$1"; shift
162 _procd_add_table_data
"$@"
165 _procd_add_array_data
"$@"
171 _procd_close_instance
() {
175 _procd_close_trigger
() {
179 _procd_add_instance
() {
181 _procd_set_command
"$@"
182 _procd_close_instance
190 [ -n "$service" ] && json_add_string name
"$service"
191 [ -n "$instance" ] && json_add_string instance
"$instance"
192 _procd_ubus_call delete
197 procd_close_service \
199 procd_add_config_trigger \
201 procd_close_trigger \
202 procd_open_instance \
203 procd_close_instance \