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"
117 _procd_open_trigger
() {
118 json_add_array
"triggers"
121 _procd_open_validate
() {
122 json_add_array
"validate"
126 local type="$1"; shift
130 _procd_add_table
"$type" "$@"
132 command|netdev|
file|respawn|watch
)
133 _procd_add_array
"$type" "$@"
136 json_add_array
"$type"
137 json_add_string
"" "$@"
141 json_add_int
"$type" "$1"
144 json_add_string
"$type" "$1"
147 json_add_boolean
"$type" "$1"
152 _procd_add_interface_trigger
() {
154 _procd_add_array_data
"$1"
158 _procd_add_array_data
"if"
161 _procd_add_array_data
"eq" "interface" "$1"
166 _procd_add_array_data
"run_script" "$@"
174 _procd_add_reload_interface_trigger
() {
175 local script=$
(readlink
"$initscript")
176 local name
=$
(basename ${script:-$initscript})
179 _procd_add_interface_trigger
"interface.*" $1 /etc
/init.d
/$name reload
183 _procd_add_config_trigger
() {
185 _procd_add_array_data
"$1"
189 _procd_add_array_data
"if"
192 _procd_add_array_data
"eq" "package" "$1"
197 _procd_add_array_data
"run_script" "$@"
205 _procd_add_raw_trigger
() {
207 _procd_add_array_data
"$1"
214 _procd_add_array_data
"run_script" "$@"
218 json_add_int
"" "$timeout"
223 _procd_add_reload_trigger
() {
224 local script=$
(readlink
"$initscript")
225 local name
=$
(basename ${script:-$initscript})
230 _procd_add_config_trigger
"config.change" "$file" /etc
/init.d
/$name reload
235 _procd_add_validation
() {
238 _procd_close_validate
241 _procd_append_param
() {
242 local type="$1"; shift
243 local _json_no_warning
=1
247 _procd_set_param
"$type" "$@"
252 _procd_add_table_data
"$@"
254 command|netdev|
file|respawn|watch
)
255 _procd_add_array_data
"$@"
258 json_add_string
"" "$@"
264 _procd_close_instance
() {
268 _procd_close_trigger
() {
272 _procd_close_validate
() {
276 _procd_add_instance
() {
278 _procd_set_param
command "$@"
279 _procd_close_instance
287 [ -n "$service" ] && json_add_string name
"$service"
288 [ -n "$instance" ] && json_add_string instance
"$instance"
289 _procd_ubus_call delete
294 json_set_namespace procd __procd_old_cb
300 json_set_namespace
$__procd_old_cb
303 _procd_set_config_changed
() {
307 json_add_string
type config.change
309 json_add_string package
"$package"
312 ubus call service event
"$(json_dump)"
315 procd_add_mdns_service
() {
316 local service proto port
320 json_add_object
"${service}_$port"
321 json_add_string
"service" "_$service._$proto.local"
322 json_add_int port
"$port"
325 for txt
in $@
; do json_add_string
"" $txt; done
333 json_add_object
"mdns"
334 procd_add_mdns_service $@
339 uci_validate_section
()
347 _result
=`/sbin/validate_data "$_package" "$_type" "$_name" "$@" 2> /dev/null`
350 [ "$_error" = "0" ] ||
`/sbin/validate_data "$_package" "$_type" "$_name" "$@" 1> /dev/null`
356 procd_close_service \
358 procd_add_raw_trigger \
359 procd_add_config_trigger \
360 procd_add_interface_trigger \
361 procd_add_reload_trigger \
362 procd_add_reload_interface_trigger \
363 procd_add_interface_reload \
365 procd_close_trigger \
366 procd_open_instance \
367 procd_close_instance \
368 procd_open_validate \
369 procd_close_validate \
372 procd_add_validation \
373 procd_set_config_changed \