Move libexpat, unbound into core and introduce hnsd
[librecmc/librecmc.git] / package / network / services / unbound / files / unbound.init
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
12 START=19
13 STOP=50
14 USE_PROCD=1
15 PROG=/usr/sbin/unbound
16
17 ##############################################################################
18
19 boot() {
20   UB_BOOT=1
21   start "$@"
22 }
23
24 ##############################################################################
25
26 start_service() {
27   if [ -n "$UB_BOOT" ] ; then
28     # Load procd triggers (rc) and use event IFUP to really start
29     return 0
30   fi
31
32   # complex UCI work
33   . /usr/lib/unbound/unbound.sh
34   unbound_start
35
36   # standard procd clause
37   procd_open_instance "unbound"
38   procd_set_param command $PROG -d -c $UB_TOTAL_CONF
39   procd_set_param respawn
40   procd_close_instance
41 }
42
43 ##############################################################################
44
45 stop_service() {
46   # clean up
47   . /usr/lib/unbound/stopping.sh
48   unbound_stop
49
50   # Wait! on restart Unbound may take time writing closure stats to syslog
51   pidof $PROG && sleep 1
52 }
53
54 ##############################################################################
55
56 service_triggers() {
57   local legacy=$( uci_get unbound.@unbound[0].trigger )
58   local triggers=$( uci_get unbound.@unbound[0].trigger_interface )
59   local trigger="$triggers $legacy"
60
61   . /usr/lib/unbound/defaults.sh
62
63
64   if [ ! -f "$UB_TOTAL_CONF" -o -n "$UB_BOOT" ] ; then
65     # Unbound is can be a bit heavy, so wait some on first start but any
66     # interface coming up affects the trigger and delay so guarantee start
67     procd_add_raw_trigger "interface.*.up" 3000 /etc/init.d/unbound restart
68
69   elif [ -n "$triggers" ] ; then
70     procd_add_reload_trigger "unbound" "dhcp"
71
72
73     for trigger in $triggers ; do
74       # User selected triggers to restart at any other time
75       procd_add_reload_interface_trigger "$trigger"
76     done
77
78   else
79     procd_add_reload_trigger "unbound" "dhcp"
80   fi
81 }
82
83 ##############################################################################
84