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 # respawn info: array with 3 values $restart_timeout $fail_hreshold $max_fail
16 # env: environment variable (passed to the process)
17 # data: arbitrary name/value pairs for detecting config changes (table)
18 # file: configuration files (array)
19 # netdev: bound network device (detects ifindex changes)
20 # limits: resource limits (passed to the process)
21 # user info: array with 1 values $username
23 # No space separation is done for arrays/tables - use one function argument per command line argument
25 # procd_close_instance():
26 # Complete the instance being prepared
28 # procd_kill(service, [instance]):
29 # Kill a service instance (or all instances)
32 .
$IPKG_INSTROOT/usr
/share
/libubox
/jshn.sh
39 json_set_namespace procd old_cb
41 json_set_namespace
$old_cb
46 eval "$1() { _procd_call _$1 \"\$@\"; }"
54 [ -n "$PROCD_DEBUG" ] && json_dump
>&2
55 ubus call service
"$cmd" "$(json_dump)"
59 _procd_open_service
() {
63 _PROCD_SERVICE
="$name"
67 json_add_string name
"$name"
68 [ -n "$script" ] && json_add_string
script "$script"
69 json_add_object instances
72 _procd_close_service
() {
78 _procd_add_array_data
() {
79 while [ "$#" -gt 0 ]; do
80 json_add_string
"" "$1"
88 _procd_add_array_data
"$@"
92 _procd_add_table_data
() {
96 [ "$1" = "$val" ] && val
=
97 json_add_string
"$var" "$val"
105 _procd_add_table_data
"$@"
109 _procd_open_instance
() {
110 local name
="$1"; shift
112 _PROCD_INSTANCE_SEQ
="$(($_PROCD_INSTANCE_SEQ + 1))"
113 name
="${name:-instance$_PROCD_INSTANCE_SEQ}"
114 json_add_object
"$name"
115 [ -n "$TRACE_SYSCALLS" ] && json_add_boolean trace
"1"
118 _procd_open_trigger
() {
119 json_add_array
"triggers"
122 _procd_open_validate
() {
123 json_add_array
"validate"
127 json_add_object
"jail"
128 json_add_string name
"$1"
129 json_add_string root
"/tmp/.jail/$1"
135 log
) json_add_boolean
"log" "1";;
136 ubus
) json_add_boolean
"ubus" "1";;
137 procfs
) json_add_boolean
"procfs" "1";;
138 sysfs
) json_add_boolean
"sysfs" "1";;
141 json_add_object
"mount"
146 _procd_add_jail_mount
() {
147 local _json_no_warning
=1
157 json_add_string
"$a" "0"
163 _procd_add_jail_mount_rw
() {
164 local _json_no_warning
=1
174 json_add_string
"$a" "1"
181 local type="$1"; shift
185 _procd_add_table
"$type" "$@"
187 command|netdev|
file|respawn|watch
)
188 _procd_add_array
"$type" "$@"
191 json_add_array
"$type"
192 json_add_string
"" "$@"
196 json_add_int
"$type" "$1"
199 json_add_string
"$type" "$1"
202 json_add_boolean
"$type" "$1"
207 _procd_add_interface_trigger
() {
209 _procd_add_array_data
"$1"
213 _procd_add_array_data
"if"
216 _procd_add_array_data
"eq" "interface" "$1"
221 _procd_add_array_data
"run_script" "$@"
228 _procd_add_reload_interface_trigger
() {
229 local script=$
(readlink
"$initscript")
230 local name
=$
(basename ${script:-$initscript})
233 _procd_add_interface_trigger
"interface.*" $1 /etc
/init.d
/$name reload
237 _procd_add_config_trigger
() {
239 _procd_add_array_data
"$1"
243 _procd_add_array_data
"if"
246 _procd_add_array_data
"eq" "package" "$1"
251 _procd_add_array_data
"run_script" "$@"
259 _procd_add_raw_trigger
() {
261 _procd_add_array_data
"$1"
268 _procd_add_array_data
"run_script" "$@"
272 json_add_int
"" "$timeout"
277 _procd_add_reload_trigger
() {
278 local script=$
(readlink
"$initscript")
279 local name
=$
(basename ${script:-$initscript})
284 _procd_add_config_trigger
"config.change" "$file" /etc
/init.d
/$name reload
289 _procd_add_validation
() {
292 _procd_close_validate
295 _procd_append_param
() {
296 local type="$1"; shift
297 local _json_no_warning
=1
301 _procd_set_param
"$type" "$@"
306 _procd_add_table_data
"$@"
308 command|netdev|
file|respawn|watch
)
309 _procd_add_array_data
"$@"
312 json_add_string
"" "$@"
318 _procd_close_instance
() {
322 _procd_close_trigger
() {
326 _procd_close_validate
() {
330 _procd_add_instance
() {
332 _procd_set_param
command "$@"
333 _procd_close_instance
341 [ -n "$service" ] && json_add_string name
"$service"
342 [ -n "$instance" ] && json_add_string instance
"$instance"
343 _procd_ubus_call delete
348 json_set_namespace procd __procd_old_cb
354 json_set_namespace
$__procd_old_cb
357 _procd_set_config_changed
() {
361 json_add_string
type config.change
363 json_add_string package
"$package"
366 ubus call service event
"$(json_dump)"
369 procd_add_mdns_service
() {
370 local service proto port
374 json_add_object
"${service}_$port"
375 json_add_string
"service" "_$service._$proto.local"
376 json_add_int port
"$port"
379 for txt
in $@
; do json_add_string
"" $txt; done
387 json_add_object
"mdns"
388 procd_add_mdns_service $@
393 uci_validate_section
()
401 _result
=`/sbin/validate_data "$_package" "$_type" "$_name" "$@" 2> /dev/null`
404 [ "$_error" = "0" ] ||
`/sbin/validate_data "$_package" "$_type" "$_name" "$@" 1> /dev/null`
410 procd_close_service \
412 procd_add_raw_trigger \
413 procd_add_config_trigger \
414 procd_add_interface_trigger \
415 procd_add_reload_trigger \
416 procd_add_reload_interface_trigger \
418 procd_close_trigger \
419 procd_open_instance \
420 procd_close_instance \
421 procd_open_validate \
422 procd_close_validate \
424 procd_add_jail_mount \
425 procd_add_jail_mount_rw \
428 procd_add_validation \
429 procd_set_config_changed \