mdns: fix ubus wait_for command
[openwrt/svn-archive/archive.git] / package / network / services / mdns / files / mdns.init
1 #!/bin/sh /etc/rc.common
2 # Copyright (c) 2014 OpenWrt.org
3
4 . /lib/functions/network.sh
5
6 START=80
7
8 USE_PROCD=1
9 PROG=/usr/sbin/mdns
10 IFACES=""
11
12 load_ifaces() {
13 local network="$(uci get mdns.@mdns[-1].network)"
14 for n in $network; do
15 local device
16 json_load "$(ifstatus $network)"
17 json_get_var device l3_device
18 echo -n "$device "
19 done
20 }
21
22 reload_service() {
23 json_init
24 json_add_array interfaces
25 for i in $(load_ifaces); do
26 json_add_string "" "$i"
27 done
28 json_close_array
29
30 ubus call mdns set_config "$(json_dump)"
31 }
32
33 start_service() {
34 local network="$(uci get mdns.@mdns[-1].network)"
35
36 procd_open_instance
37 procd_set_param command "$PROG"
38 procd_set_param seccomp /etc/seccomp/mdns.json
39 procd_set_param respawn
40 procd_open_trigger
41 procd_add_config_trigger "config.change" "mdns" /etc/init.d/mdns reload
42 for n in $network; do
43 procd_add_interface_trigger "interface.*" $n /etc/init.d/mdns reload
44 done
45 procd_add_raw_trigger "instance.update" 5000 "/bin/ubus" "call" "mdns" "reload"
46 procd_close_trigger
47 [ "$(uci get mdns.@mdns[-1].jail)" = 1 ] && procd_add_jail mdns ubus log
48 procd_close_instance
49 }
50
51 service_started() {
52 ubus -t 10 wait_for mdns
53 [ $? = 0 ] && reload_service
54 }