packages/net/unbound/files/unbound.init
Eric Luehrsen 8830d72bbd unbound: fix boot time and default run directory
Unbound struggles with boot ifup, so procd triggers changed to push
outside of this noise. Unbound has run in /var/lib/unbound/, so chroot
(jail) protects /etc/, and it can save flash wear. Compiled defaults
reflect this now, so Unbound tools are easier run on the command line.

Signed-off-by: Eric Luehrsen <ericluehrsen@gmail.com>
2018-08-03 03:27:03 -04:00

86 lines
2.2 KiB
Bash
Executable file

#!/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" -o -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" 5000 /etc/init.d/unbound restart
elif [ -n "$triggers" ] ; then
PROCD_RELOAD_DELAY=2000
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_RELOAD_DELAY=2000
procd_add_reload_trigger "unbound" "dhcp"
fi
}
##############################################################################