summaryrefslogtreecommitdiff
path: root/package/network/services/mdns/files/mdns.init
blob: f66de11d3feedd9c009757d8f28a5203a1de5e13 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/sh /etc/rc.common
# Copyright (c) 2014 OpenWrt.org

. /lib/functions/network.sh

START=80

USE_PROCD=1
PROG=/usr/sbin/mdns
IFACES=""

load_ifaces() {
	local network="$(uci get mdns.@mdns[-1].network)"
	for n in $network; do
		local device
		json_load "$(ifstatus $network)"
		json_get_var device l3_device
		echo -n "$device "
	done
}

reload_service() {
	json_init
	json_add_array interfaces
	for i in $(load_ifaces); do
		json_add_string "" "$i"
	done
	json_close_array

	ubus call mdns set_config "$(json_dump)"
}

start_service() {
	local network="$(uci get mdns.@mdns[-1].network)"

	procd_open_instance
	procd_set_param command "$PROG"
	procd_set_param respawn
	procd_open_trigger
	procd_add_config_trigger "config.change" "mdns" /etc/init.d/mdns reload
	for n in $network; do
		procd_add_interface_trigger "interface.*" $n /etc/init.d/mdns reload	
	done
	procd_close_trigger
	procd_close_instance
}

service_started() {
	ubus wait_for -t 5 mdns
	[ $? = 0 ] && reload_service
}