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)
21 # No space separation is done for arrays/tables - use one function argument per command line argument
23 # procd_close_instance():
24 # Complete the instance being prepared
26 # procd_kill(service, [instance]):
27 # Kill a service instance (or all instances)
30 . $IPKG_INSTROOT/usr/share/libubox/jshn.sh
37 json_set_namespace procd old_cb
39 json_set_namespace $old_cb
44 eval "$1() { _procd_call _$1 \"\$@\"; }"
52 ubus call service "$cmd" "$(json_dump)"
56 _procd_open_service() {
60 _PROCD_SERVICE="$name"
64 json_add_string name "$name"
65 [ -n "$script" ] && json_add_string script "$script"
66 json_add_object instances
69 _procd_close_service() {
75 _procd_add_array_data() {
77 json_add_string "" "$1"
85 _procd_add_array_data "$@"
89 _procd_add_table_data() {
93 [[ "$1" == "$val" ]] && val=
94 json_add_string "$var" "$val"
102 _procd_add_table_data "$@"
106 _procd_open_instance() {
107 local name="$1"; shift
109 _PROCD_INSTANCE_SEQ="$(($_PROCD_INSTANCE_SEQ + 1))"
110 name="${name:-instance$_PROCD_INSTANCE_SEQ}"
111 json_add_object "$name"
114 _procd_open_trigger() {
115 json_add_array "triggers"
118 _procd_open_validate() {
119 json_add_array "validate"
123 local type="$1"; shift
127 _procd_add_table "$type" "$@"
129 command|netdev|file|respawn)
130 _procd_add_array "$type" "$@"
133 json_add_int "$type" "$1"
138 _procd_add_config_trigger() {
140 _procd_add_array_data "$1"
144 _procd_add_array_data "if"
147 _procd_add_array_data "eq" "package" "$1"
152 _procd_add_array_data "run_script" "$@"
160 _procd_add_reload_trigger() {
161 local script=$(readlink "$initscript")
162 local name=$(basename ${script:-$initscript})
165 _procd_add_config_trigger "config.change" $1 /etc/init.d/$name reload
169 _procd_add_validation() {
172 _procd_close_validate
175 _procd_append_param() {
176 local type="$1"; shift
181 _procd_add_table_data "$@"
183 command|netdev|file|respawn)
184 _procd_add_array_data "$@"
190 _procd_close_instance() {
194 _procd_close_trigger() {
198 _procd_close_validate() {
202 _procd_add_instance() {
204 _procd_set_param command "$@"
205 _procd_close_instance
213 [ -n "$service" ] && json_add_string name "$service"
214 [ -n "$instance" ] && json_add_string instance "$instance"
215 _procd_ubus_call delete
218 uci_validate_section()
222 [ "$4" = "" ] && return 1
225 json_add_string "package" "$1"
226 json_add_string "type" "$2"
227 json_add_object "data"
231 while [ -n "$1" ]; do
232 json_add_string "${1%:*}" "${1#*:}"
245 while [ -n "$1" ]; do
248 local type=${tmp%%:*}
251 [ "$tmp" = "$type" ] || default=${tmp#*:}
254 config_get "${name}" "${section}" "${name}"
257 [ "$type" = "bool" ] && {
259 1|on|true|enabled) val=1;;
260 0|off|false|disabled) val=0;;
264 [ -z "$val" ] && val=${default}
267 /sbin/validate_data "${type}" "${val}"
268 [ $? -eq 0 ] || error="$((error + 1))"
277 procd_close_service \
279 procd_add_config_trigger \
280 procd_add_reload_trigger \
282 procd_close_trigger \
283 procd_open_instance \
284 procd_close_instance \
287 procd_add_validation \