umdns.init 1.2 KB

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