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
() {
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"
121 local type="$1"; shift
125 _procd_add_table
"$type" "$@"
127 command|netdev|
file|respawn
)
128 _procd_add_array
"$type" "$@"
131 json_add_int
"$type" "$1"
136 _procd_add_config_trigger
() {
138 _procd_add_array_data
"config.change"
141 _procd_add_array_data
"if"
144 _procd_add_array_data
"eq" "package" "$1"
149 _procd_add_array_data
"run_script" "$@"
157 _procd_add_reload_trigger
() {
158 local script=$
(readlink
"$initscript")
159 local name
=$
(basename ${script:-$initscript})
161 _procd_add_config_trigger
$1 /etc
/init.d
/$name reload
164 _procd_add_reload_trigger
() {
165 local script=$
(readlink
"$initscript")
166 local name
=$
(basename ${script:-$initscript})
168 _procd_add_config_trigger
$1 /etc
/init.d
/$name reload
171 _procd_append_param
() {
172 local type="$1"; shift
177 _procd_add_table_data
"$@"
179 command|netdev|
file|respawn
)
180 _procd_add_array_data
"$@"
186 _procd_close_instance
() {
190 _procd_close_trigger
() {
194 _procd_add_instance
() {
196 _procd_set_command
"$@"
197 _procd_close_instance
205 [ -n "$service" ] && json_add_string name
"$service"
206 [ -n "$instance" ] && json_add_string instance
"$instance"
207 _procd_ubus_call delete
212 procd_close_service \
214 procd_add_config_trigger \
215 procd_add_reload_trigger \
217 procd_close_trigger \
218 procd_open_instance \
219 procd_close_instance \