aboutsummaryrefslogtreecommitdiff
path: root/net/unbound/files/unbound.init
blob: e76f68cd1a4f2d68d5aa3ae4e0618b27d26a051e (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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/bin/sh /etc/rc.common
##############################################################################
#
# Copyright (C) 2016 Michael Hanselmann, Eric Luehrsen
#
##############################################################################
#
# This init script is just the entry point for Unbound UCI.
#
##############################################################################

START=19
STOP=50
USE_PROCD=1
PROG=/usr/sbin/unbound

##############################################################################

boot() {
  UB_BOOT=1
  start "$@"
}

##############################################################################

start_service() {
  if [ -n "$UB_BOOT" ] ; then
    # Load procd triggers (rc) and use event IFUP to really start
    return 0
  fi

  # complex UCI work
  . /usr/lib/unbound/unbound.sh
  unbound_start

  # standard procd clause
  procd_open_instance "unbound"
  procd_set_param command $PROG -d -c $UB_TOTAL_CONF
  procd_set_param respawn
  procd_close_instance
}

##############################################################################

stop_service() {
  # clean up
  . /usr/lib/unbound/stopping.sh
  unbound_stop

  # Wait! on restart Unbound may take time writing closure stats to syslog
  pidof $PROG && sleep 1
}

##############################################################################

service_triggers() {
  local legacy=$( uci_get unbound.@unbound[0].trigger )
  local triggers=$( uci_get unbound.@unbound[0].trigger_interface )
  local trigger="$triggers $legacy"

  . /usr/lib/unbound/defaults.sh


  if [ ! -f "$UB_TOTAL_CONF" ] || [ -n "$UB_BOOT" ] ; then
    # Unbound is can be a bit heavy, so wait some on first start but any
    # interface coming up affects the trigger and delay so guarantee start
    procd_add_raw_trigger "interface.*.up" 3000 /etc/init.d/unbound restart

  elif [ -n "$triggers" ] ; then
    procd_add_reload_trigger "unbound" "dhcp"


    for trigger in $triggers ; do
      # User selected triggers to restart at any other time
      procd_add_reload_interface_trigger "$trigger"
    done

  else
    procd_add_reload_trigger "unbound" "dhcp"
  fi
}

##############################################################################