Start/Stop Script Ubuntu 16.04 [Help]

Hi,

I need help about the start/stop/restart script for Ubuntu 16.04.7 LTS

I’ve installed unbound 1.13.0 from source:

  • This link help me a lot: http://linuxfromscratch.org/blfs/view/systemd/server/unbound.html

  • Dependencies + make + make install were all succeeded
    apt-get install make gcc libssl-dev libevent-dev libexpat1-dev libldns-dev

  • group + user unbound created

  • unbound + unbound-anchor + unbound-checkconf + unbound-control + unbound-control-setup + unbound-host located at /usr/local/sbin

  • unbound.conf installed at /etc/unbound/ with parameter --with-conf-file=/etc/unbound/unbound.conf during configure

  • then I’ve created the script /etc/init.d/unbound like this:

#!/bin/sh

BEGIN INIT INFO

Provides: unbound

Required-Start: $network $remote_fs $syslog

Required-Stop: $network $remote_fs $syslog

Default-Start: 2 3 4 5

Default-Stop: 0 1 6

END INIT INFO

NAME=“unbound”
DESC=“DNS server”
DAEMON=“/usr/local/sbin/unbound”
PIDFILE=“/run/unbound.pid”

HELPER=“/usr/local/lib/unbound/package-helper”

test -x $DAEMON || exit 0

. /lib/lsb/init-functions

Override this variable by editing or creating /etc/default/unbound.

DAEMON_OPTS=“”

if [ -f /etc/default/unbound ]; then
. /etc/default/unbound
fi

case “$1” in
start)
log_daemon_msg “Starting $DESC” “$NAME”
$HELPER chroot_setup
$HELPER root_trust_anchor_update 2>&1 | logger -p daemon.info -t unbound-anchor
if start-stop-daemon --start --quiet --oknodo --pidfile $PIDFILE --name $NAME --startas $DAEMON – $DAEMON_OPTS; then
$HELPER resolvconf_start
log_end_msg 0
else
log_end_msg 1
fi
;;

stop)
log_daemon_msg “Stopping $DESC” “$NAME”
if start-stop-daemon --stop --quiet --oknodo --pidfile $PIDFILE --name $NAME; then
$HELPER resolvconf_stop
log_end_msg 0
else
log_end_msg 1
fi
;;

restart>force-reload)
log_daemon_msg “Restarting $DESC” “$NAME”
start-stop-daemon --stop --quiet --pidfile $PIDFILE --name $NAME --retry 5
$HELPER resolvconf_stop
if start-stop-daemon --start --quiet --oknodo --pidfile $PIDFILE --name $NAME --startas $DAEMON – $DAEMON_OPTS; then
$HELPER chroot_setup
$HELPER resolvconf_start
log_end_msg 0
else
log_end_msg 1
fi
;;

reload)
log_daemon_msg “Reloading $DESC” “$NAME”
if start-stop-daemon --stop --pidfile $PIDFILE --signal 1; then
$HELPER chroot_setup
log_end_msg 0
else
log_end_msg 1
fi
;;

status)
status_of_proc -p $PIDFILE $DAEMON $NAME && exit 0 || exit $?
;;

*)
N=/etc/init.d/$NAME
echo “Usage: $N {start|stop|restart|status|reload|force-reload}” >&2
exit 1
;;
esac

exit 0

try:
chmod +x /etc/init.d/unbound
/etc/init.d/unbound start

you created an SYS-V init.d style start script and then asked systemd to start a service
init.d and systemd do not necessarily have a relation...

in general: this is not a unbound related issue. Read about starting system services.

Andreas

Thank you very much for your answer.

After reading about starting system services I noticed I missed an important step of service installation:

root@unbound:/# update-rc.d unbound defaults

After that service is up and running:

root@unbound:/etc/init.d# service unbound start
root@unbound:/etc/init.d# service unbound status
● unbound.service
Loaded: loaded (/etc/init.d/unbound; bad; vendor preset: enabled)
Drop-In: /run/systemd/generator/unbound.service.d
└─50-insserv.conf-$named.conf
Active: active (running) since Tue 2020-12-29 15:11:22 -04; 1s ago
Docs: man:systemd-sysv-generator(8)
Process: 18176 ExecStart=/etc/init.d/unbound start (code=exited, status=0/SUCCESS)
Tasks: 1
Memory: 3.1M
CPU: 60ms
CGroup: /system.slice/unbound.service
└─18187 /usr/sbin/unbound

Dec 29 15:11:22 dns-nmm-02 systemd[1]: Starting unbound.service…
Dec 29 15:11:22 dns-nmm-02 unbound[18176]: * Starting DNS server unbound
Dec 29 15:11:22 dns-nmm-02 unbound[18176]: /etc/init.d/unbound: 32: /etc/init.d/unbound: /usr/lib/unbound/package-helper: not found
Dec 29 15:11:22 dns-nmm-02 unbound[18176]: /etc/init.d/unbound: 35: /etc/init.d/unbound: /usr/lib/unbound/package-helper: not found
Dec 29 15:11:22 dns-nmm-02 unbound[18176]: …done.
Dec 29 15:11:22 dns-nmm-02 systemd[1]: Started unbound.service.
Dec 29 15:11:22 dns-nmm-02 unbound[18187]: [18187:0] notice: init module 0: validator
Dec 29 15:11:22 dns-nmm-02 unbound[18187]: [18187:0] notice: init module 1: iterator
Dec 29 15:11:22 dns-nmm-02 unbound[18187]: [18187:0] info: start of service (unbound 1.13.0).