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)
22 # No space separation is done for arrays/tables - use one function argument per command line argument
24 # procd_close_instance():
25 # Complete the instance being prepared
27 # procd_kill(service, [instance]):
28 # Kill a service instance (or all instances)
31 . $IPKG_INSTROOT/usr/share/libubox/jshn.sh
38 json_set_namespace procd old_cb
40 json_set_namespace $old_cb
45 eval "$1() { _procd_call _$1 \"\$@\"; }"
53 [ -n "$PROCD_DEBUG" ] && json_dump >&2
54 ubus call service "$cmd" "$(json_dump)"
58 _procd_open_service() {
62 _PROCD_SERVICE="$name"
66 json_add_string name "$name"
67 [ -n "$script" ] && json_add_string script "$script"
68 json_add_object instances
71 _procd_close_service() {
77 _procd_add_array_data() {
79 json_add_string "" "$1"
87 _procd_add_array_data "$@"
91 _procd_add_table_data() {
95 [[ "$1" == "$val" ]] && val=
96 json_add_string "$var" "$val"
104 _procd_add_table_data "$@"
108 _procd_open_instance() {
109 local name="$1"; shift
111 _PROCD_INSTANCE_SEQ="$(($_PROCD_INSTANCE_SEQ + 1))"
112 name="${name:-instance$_PROCD_INSTANCE_SEQ}"
113 json_add_object "$name"
116 _procd_open_trigger() {
117 json_add_array "triggers"
120 _procd_open_validate() {
121 json_add_array "validate"
125 local type="$1"; shift
129 _procd_add_table "$type" "$@"
131 command|netdev|file|respawn|watch)
132 _procd_add_array "$type" "$@"
135 json_add_array "$type"
136 json_add_string "" "$@"
140 json_add_int "$type" "$1"
145 _procd_add_interface_trigger() {
147 _procd_add_array_data "$1"
151 _procd_add_array_data "if"
154 _procd_add_array_data "eq" "interface" "$1"
159 _procd_add_array_data "run_script" "$@"
167 _procd_add_reload_interface_trigger() {
168 local script=$(readlink "$initscript")
169 local name=$(basename ${script:-$initscript})
172 _procd_add_interface_trigger "interface.*" $1 /etc/init.d/$name reload
176 _procd_add_config_trigger() {
178 _procd_add_array_data "$1"
182 _procd_add_array_data "if"
185 _procd_add_array_data "eq" "package" "$1"
190 _procd_add_array_data "run_script" "$@"
198 _procd_add_reload_trigger() {
199 local script=$(readlink "$initscript")
200 local name=$(basename ${script:-$initscript})
205 _procd_add_config_trigger "config.change" "$file" /etc/init.d/$name reload
210 _procd_add_validation() {
213 _procd_close_validate
216 _procd_append_param() {
217 local type="$1"; shift
218 local _json_no_warning=1
222 _procd_set_param "$type" "$@"
227 _procd_add_table_data "$@"
229 command|netdev|file|respawn|watch)
230 _procd_add_array_data "$@"
233 json_add_string "" "$@"
239 _procd_close_instance() {
243 _procd_close_trigger() {
247 _procd_close_validate() {
251 _procd_add_instance() {
253 _procd_set_param command "$@"
254 _procd_close_instance
262 [ -n "$service" ] && json_add_string name "$service"
263 [ -n "$instance" ] && json_add_string instance "$instance"
264 _procd_ubus_call delete
269 json_set_namespace procd __procd_old_cb
275 json_set_namespace $__procd_old_cb
278 _procd_set_config_changed() {
282 json_add_string type config.change
284 json_add_string package "$package"
287 ubus call service event "$(json_dump)"
290 uci_validate_section()
298 _result=`/sbin/validate_data "$_package" "$_type" "$_name" "$@" 2> /dev/null`
301 [ "$_error" = "0" ] || `/sbin/validate_data "$_package" "$_type" "$_name" "$@" 1> /dev/null`
307 procd_close_service \
309 procd_add_config_trigger \
310 procd_add_interface_trigger \
311 procd_add_reload_trigger \
312 procd_add_reload_interface_trigger \
313 procd_add_interface_reload \
315 procd_close_trigger \
316 procd_open_instance \
317 procd_close_instance \
318 procd_open_validate \
319 procd_close_validate \
322 procd_add_validation \
323 procd_set_config_changed \