59cea9
#!/bin/sh
59cea9
#
59cea9
# unbound	This shell script takes care of starting and stopping
59cea9
#		unbound (DNS server).
59cea9
#
59cea9
# chkconfig:   - 14 86
59cea9
# description:	unbound is a Domain Name Server (DNS) \
59cea9
#		that is used to resolve host names to IP addresses.
59cea9
59cea9
### BEGIN INIT INFO
59cea9
# Provides: unbound
59cea9
# Required-Start: $network $local_fs
59cea9
# Required-Stop: $network $local_fs
59cea9
# Default-Start:
59cea9
# Default-Stop: 0 1 2 3 4 5 6
59cea9
# Should-Start: $syslog
59cea9
# Should-Stop: $syslog
59cea9
# Short-Description: unbound recursive Domain Name Server.
59cea9
# Description:  unbound is a Domain Name Server (DNS) 
59cea9
#		that is used to resolve host names to IP addresses.
59cea9
### END INIT INFO
59cea9
59cea9
# Source function library.
59cea9
. /etc/rc.d/init.d/functions
59cea9
59cea9
exec="/usr/sbin/unbound"
59cea9
config="/etc/unbound/unbound.conf"
59cea9
pidfile="/var/run/unbound/unbound.pid"
59cea9
piddir=`dirname $pidfile`
59cea9
59cea9
[ -e /etc/sysconfig/unbound ] && . /etc/sysconfig/unbound
59cea9
[ -e /etc/sysconfig/dnssec ] && . /etc/sysconfig/dnssec
59cea9
59cea9
lockfile=/var/lock/subsys/unbound
59cea9
59cea9
[ -x /usr/sbin/dnssec-configure ] && [ -r "$config" ] &&
59cea9
  [ /etc/sysconfig/dnssec -nt "$config" ] && \
59cea9
    /usr/sbin/dnssec-configure -u --norestart --dnssec="$DNSSEC" --dlv="$DLV"
59cea9
59cea9
start() {
59cea9
    [ -x $exec ] || exit 5
59cea9
    [ -f $config ] || exit 6
59cea9
    # /var/run could (and should) be tmpfs
59cea9
    [ -d $piddir ] || mkdir $piddir
59cea9
59cea9
    if [ -f /var/lib/unbound/root.anchor -a -f /usr/sbin/unbound-anchor ]
59cea9
    then
59cea9
	/sbin/runuser --command="/usr/sbin/unbound-anchor -a /var/lib/unbound/root.anchor -c /etc/unbound/icannbundle.pem" --shell /bin/sh unbound
59cea9
    fi
59cea9
59cea9
    if [ ! -f /etc/unbound/unbound_control.key ]
59cea9
    then
59cea9
	echo -n $"Generating unbound control key and certificate: "
59cea9
	/usr/sbin/unbound-control-setup -d /etc/unbound/ > /dev/null 2> /dev/null
59cea9
	chgrp unbound /etc/unbound/unbound_*key /etc/unbound/unbound_*pem
59cea9
	[ -x /usr/sbin/selinuxenabled ] && /usr/sbin/selinuxenabled && \
59cea9
	    [ -x /sbin/restorecon ] && /sbin/restorecon /etc/unbound/*
59cea9
	echo
59cea9
    else
59cea9
	# old init script created these as root instead of unbound.
59cea9
	if [ -G /etc/unbound/unbound_control.key ]
59cea9
	then
59cea9
	    chgrp unbound /etc/unbound/unbound_*key /etc/unbound/unbound_*pem
59cea9
	    [ -x /usr/sbin/selinuxenabled ] && /usr/sbin/selinuxenabled && \
59cea9
		[ -x /sbin/restorecon ] && /sbin/restorecon /etc/unbound/*
59cea9
	    echo
59cea9
	fi
59cea9
    fi
59cea9
59cea9
59cea9
    unbound-checkconf $config > /dev/null
59cea9
    RETVAL=$?
59cea9
    if [ $RETVAL != 0 ]
59cea9
    then
59cea9
	echo "Error in /etc/unbound/unbound.conf, aborted"
59cea9
	exit 6
59cea9
    fi
59cea9
59cea9
    echo -n $"Starting unbound: "
59cea9
59cea9
    # if not running, start it up here
59cea9
    daemon --pidfile=$pidfile $exec -c $config
59cea9
    retval=$?
59cea9
    [ $retval -eq 0 ] && touch $lockfile
59cea9
    echo
59cea9
}
59cea9
59cea9
stop() {
59cea9
    echo -n $"Stopping unbound: "
59cea9
    # stop it here, often "killproc unbound"
59cea9
    killproc -p $pidfile unbound
59cea9
    retval=$?
59cea9
    [ $retval -eq 0 ] && rm -f $lockfile
59cea9
    echo
59cea9
}
59cea9
59cea9
restart() {
59cea9
    unbound-checkconf $config > /dev/null
59cea9
    RETVAL=$?
59cea9
    if [ $RETVAL != 0 ]
59cea9
    then
59cea9
	echo "Error in /etc/unbound/unbound.conf, aborted"
59cea9
	exit 6
59cea9
    fi
59cea9
    stop
59cea9
    start
59cea9
}
59cea9
59cea9
reload() {
59cea9
    #kill -HUP `cat $pidfile`
59cea9
    # See rhbz#489278
59cea9
    restart
59cea9
}
59cea9
59cea9
force_reload() {
59cea9
    restart
59cea9
}
59cea9
59cea9
rh_status() {
59cea9
    # run checks to determine if the service is running or use generic status
59cea9
    status -p $pidfile unbound
59cea9
}
59cea9
59cea9
rh_status_q() {
59cea9
    rh_status -p $pidfile >/dev/null 2>&1
59cea9
}
59cea9
59cea9
case "$1" in
59cea9
    start)
59cea9
        start
59cea9
        ;;
59cea9
    stop)
59cea9
        stop
59cea9
        ;;
59cea9
    restart)
59cea9
        restart
59cea9
        ;;
59cea9
    reload)
59cea9
        reload
59cea9
        ;;
59cea9
    force-reload)
59cea9
        force_reload
59cea9
        ;;
59cea9
    status)
59cea9
        rh_status
59cea9
        ;;
59cea9
    condrestart|try-restart)
59cea9
        rh_status_q || exit 0
59cea9
        restart
59cea9
        ;;
59cea9
    *)
59cea9
        echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
59cea9
        exit 2
59cea9
esac
59cea9
exit $?