You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

87 lines
2.3 KiB

  1. #!/bin/sh /etc/rc.common
  2. ##############################################################################
  3. #
  4. # Copyright (C) 2016 Michael Hanselmann, Eric Luehrsen
  5. #
  6. ##############################################################################
  7. #
  8. # This init script is just the entry point for Unbound UCI.
  9. #
  10. ##############################################################################
  11. # while useful (sh)ellcheck is pedantic and noisy
  12. # shellcheck disable=1091,2002,2004,2034,2039,2086,2094,2140,2154,2155
  13. START=19
  14. STOP=50
  15. USE_PROCD=1
  16. PROG=/usr/sbin/unbound
  17. ##############################################################################
  18. boot() {
  19. UB_BOOT=1
  20. start "$@"
  21. }
  22. ##############################################################################
  23. start_service() {
  24. if [ -n "$UB_BOOT" ] ; then
  25. # Load procd triggers (rc) and use event IFUP to really start
  26. return 0
  27. fi
  28. # complex UCI work
  29. . /usr/lib/unbound/unbound.sh
  30. unbound_start
  31. # standard procd clause
  32. procd_open_instance "unbound"
  33. procd_set_param command $PROG -d -c $UB_TOTAL_CONF
  34. procd_set_param respawn
  35. procd_close_instance
  36. }
  37. ##############################################################################
  38. stop_service() {
  39. # clean up
  40. . /usr/lib/unbound/stopping.sh
  41. unbound_stop
  42. # Wait! on restart Unbound may take time writing closure stats to syslog
  43. pidof $PROG && sleep 1
  44. }
  45. ##############################################################################
  46. service_triggers() {
  47. local legacy1=$( uci_get unbound.@unbound[0].trigger )
  48. local legacy2=$( uci_get unbound.@unbound[0].trigger_interface )
  49. local legacy3=$( uci_get unbound.@unbound[0].iface_trig )
  50. local triggers="$legacy1 $legacy2 $legacy3"
  51. . /usr/lib/unbound/defaults.sh
  52. if [ ! -f "$UB_TOTAL_CONF" ] || [ -n "$UB_BOOT" ] ; then
  53. # Unbound can be a bit heavy, so wait some on first start. Any interface
  54. # up affects the trigger delay and will guarantee start.
  55. procd_add_raw_trigger "interface.*.up" 3000 /etc/init.d/unbound restart
  56. elif [ -n "$triggers" ] ; then
  57. for trigger in $triggers ; do
  58. # User selected triggers to restart at any other time
  59. procd_add_reload_interface_trigger "$trigger"
  60. done
  61. procd_add_reload_trigger "unbound" "dhcp"
  62. else
  63. procd_add_reload_trigger "unbound" "dhcp"
  64. fi
  65. }
  66. ##############################################################################