Merge pull request #11353 from kvuorine/fwknop-fixes
[feed/packages.git] / net / 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" ] || [ -n "$UB_BOOT" ] ; then
65 # Unbound can be a bit heavy, so wait some on first start. Any interface
66 # up affects the trigger delay and will guarantee start.
67 procd_add_raw_trigger "interface.*.up" 3000 /etc/init.d/unbound restart
68
69 elif [ -n "$triggers" ] ; then
70 for trigger in $triggers ; do
71 # User selected triggers to restart at any other time
72 procd_add_reload_interface_trigger "$trigger"
73 done
74
75 procd_add_reload_trigger "unbound" "dhcp"
76
77 else
78 procd_add_reload_trigger "unbound" "dhcp"
79 fi
80 }
81
82 ##############################################################################
83