18f76bb7dSCy Schubert#!/bin/sh 28f76bb7dSCy Schubert# 38f76bb7dSCy Schubert# unbound This shell script takes care of starting and stopping 48f76bb7dSCy Schubert# unbound (DNS server). 58f76bb7dSCy Schubert# 68f76bb7dSCy Schubert# chkconfig: - 14 86 78f76bb7dSCy Schubert# description: unbound is a Domain Name Server (DNS) \ 88f76bb7dSCy Schubert# that is used to resolve host names to IP addresses. 98f76bb7dSCy Schubert 108f76bb7dSCy Schubert### BEGIN INIT INFO 118f76bb7dSCy Schubert# Provides: $named unbound 128f76bb7dSCy Schubert# Required-Start: $network $local_fs 138f76bb7dSCy Schubert# Required-Stop: $network $local_fs 148f76bb7dSCy Schubert# Should-Start: $syslog 158f76bb7dSCy Schubert# Should-Stop: $syslog 168f76bb7dSCy Schubert# Short-Description: unbound recursive Domain Name Server. 178f76bb7dSCy Schubert# Description: unbound is a Domain Name Server (DNS) 188f76bb7dSCy Schubert# that is used to resolve host names to IP addresses. 198f76bb7dSCy Schubert### END INIT INFO 208f76bb7dSCy Schubert 218f76bb7dSCy Schubert# Source function library. 228f76bb7dSCy Schubert. /etc/init.d/functions 238f76bb7dSCy Schubert 248f76bb7dSCy Schubertexec="/usr/sbin/unbound" 258f76bb7dSCy Schubertprog="unbound" 268f76bb7dSCy Schubertconfig="/etc/unbound/unbound.conf" 278f76bb7dSCy Schubertpidfile="/var/unbound/unbound.pid" 288f76bb7dSCy Schubertrootdir="/var/unbound" 298f76bb7dSCy Schubert 308f76bb7dSCy Schubert[ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog 318f76bb7dSCy Schubert 328f76bb7dSCy Schubertlockfile=/var/lock/subsys/$prog 338f76bb7dSCy Schubert 348f76bb7dSCy Schubertstart() { 358f76bb7dSCy Schubert [ -x $exec ] || exit 5 368f76bb7dSCy Schubert [ -f $config ] || exit 6 378f76bb7dSCy Schubert echo -n $"Starting $prog: " 388f76bb7dSCy Schubert 398f76bb7dSCy Schubert # setup root jail 408f76bb7dSCy Schubert if [ -s /etc/localtime ]; then 418f76bb7dSCy Schubert [ -d ${rootdir}/etc ] || mkdir -p ${rootdir}/etc ; 428f76bb7dSCy Schubert if [ ! -e ${rootdir}/etc/localtime ] || ! /usr/bin/cmp -s /etc/localtime ${rootdir}/etc/localtime; then 438f76bb7dSCy Schubert cp -fp /etc/localtime ${rootdir}/etc/localtime 448f76bb7dSCy Schubert fi; 458f76bb7dSCy Schubert fi; 468f76bb7dSCy Schubert if [ -s /etc/resolv.conf ]; then 478f76bb7dSCy Schubert [ -d ${rootdir}/etc ] || mkdir -p ${rootdir}/etc ; 488f76bb7dSCy Schubert if [ ! -e ${rootdir}/etc/resolv.conf ] || ! /usr/bin/cmp -s /etc/resolv.conf ${rootdir}/etc/resolv.conf; then 498f76bb7dSCy Schubert cp -fp /etc/resolv.conf ${rootdir}/etc/resolv.conf 508f76bb7dSCy Schubert fi; 518f76bb7dSCy Schubert fi; 528f76bb7dSCy Schubert if ! egrep -q '^/[^[:space:]]+[[:space:]]+'${rootdir}'/dev/log' /proc/mounts; then 538f76bb7dSCy Schubert [ -d ${rootdir}/dev ] || mkdir -p ${rootdir}/dev ; 548f76bb7dSCy Schubert [ -e ${rootdir}/dev/log ] || touch ${rootdir}/dev/log 558f76bb7dSCy Schubert mount --bind -n /dev/log ${rootdir}/dev/log >/dev/null 2>&1; 568f76bb7dSCy Schubert fi; 578f76bb7dSCy Schubert if ! egrep -q '^/[^[:space:]]+[[:space:]]+'${rootdir}'/dev/random' /proc/mounts; then 588f76bb7dSCy Schubert [ -d ${rootdir}/dev ] || mkdir -p ${rootdir}/dev ; 598f76bb7dSCy Schubert [ -e ${rootdir}/dev/random ] || touch ${rootdir}/dev/random 608f76bb7dSCy Schubert mount --bind -n /dev/random ${rootdir}/dev/random >/dev/null 2>&1; 618f76bb7dSCy Schubert fi; 628f76bb7dSCy Schubert 638f76bb7dSCy Schubert # if not running, start it up here 648f76bb7dSCy Schubert daemonize $exec 658f76bb7dSCy Schubert retval=$? 668f76bb7dSCy Schubert echo 678f76bb7dSCy Schubert [ $retval -eq 0 ] && touch $lockfile 688f76bb7dSCy Schubert return $retval 698f76bb7dSCy Schubert} 708f76bb7dSCy Schubert 718f76bb7dSCy Schubertstop() { 728f76bb7dSCy Schubert echo -n $"Stopping $prog: " 738f76bb7dSCy Schubert # stop it here, often "killproc $prog" 748f76bb7dSCy Schubert killproc $prog 758f76bb7dSCy Schubert retval=$? 768f76bb7dSCy Schubert echo 778f76bb7dSCy Schubert [ $retval -eq 0 ] && rm -f $lockfile 78*335c7cdaSCy Schubert [ $retval -eq 0 ] && rm -f $pidfile 798f76bb7dSCy Schubert if egrep -q '^/[^[:space:]]+[[:space:]]+'${rootdir}'/dev/log' /proc/mounts; then 808f76bb7dSCy Schubert umount ${rootdir}/dev/log >/dev/null 2>&1 818f76bb7dSCy Schubert fi; 828f76bb7dSCy Schubert if egrep -q '^/[^[:space:]]+[[:space:]]+'${rootdir}'/dev/random' /proc/mounts; then 838f76bb7dSCy Schubert umount ${rootdir}/dev/random >/dev/null 2>&1 848f76bb7dSCy Schubert fi; 858f76bb7dSCy Schubert return $retval 868f76bb7dSCy Schubert} 878f76bb7dSCy Schubert 888f76bb7dSCy Schubertrestart() { 898f76bb7dSCy Schubert stop 908f76bb7dSCy Schubert start 918f76bb7dSCy Schubert} 928f76bb7dSCy Schubert 938f76bb7dSCy Schubertreload() { 948f76bb7dSCy Schubert kill -HUP `cat $pidfile` 958f76bb7dSCy Schubert} 968f76bb7dSCy Schubert 978f76bb7dSCy Schubertforce_reload() { 988f76bb7dSCy Schubert restart 998f76bb7dSCy Schubert} 1008f76bb7dSCy Schubert 1018f76bb7dSCy Schubertrh_status() { 1028f76bb7dSCy Schubert # run checks to determine if the service is running or use generic status 1038f76bb7dSCy Schubert status $prog 1048f76bb7dSCy Schubert} 1058f76bb7dSCy Schubert 1068f76bb7dSCy Schubertrh_status_q() { 1078f76bb7dSCy Schubert rh_status -p $pidfile >/dev/null 2>&1 1088f76bb7dSCy Schubert} 1098f76bb7dSCy Schubert 1108f76bb7dSCy Schubertcase "$1" in 1118f76bb7dSCy Schubert start) 1128f76bb7dSCy Schubert rh_status_q && exit 0 1138f76bb7dSCy Schubert $1 1148f76bb7dSCy Schubert ;; 1158f76bb7dSCy Schubert stop) 1168f76bb7dSCy Schubert rh_status_q || exit 0 1178f76bb7dSCy Schubert $1 1188f76bb7dSCy Schubert ;; 1198f76bb7dSCy Schubert restart) 1208f76bb7dSCy Schubert $1 1218f76bb7dSCy Schubert ;; 1228f76bb7dSCy Schubert reload) 1238f76bb7dSCy Schubert rh_status_q || exit 7 1248f76bb7dSCy Schubert $1 1258f76bb7dSCy Schubert ;; 1268f76bb7dSCy Schubert force-reload) 1278f76bb7dSCy Schubert force_reload 1288f76bb7dSCy Schubert ;; 1298f76bb7dSCy Schubert status) 1308f76bb7dSCy Schubert rh_status 1318f76bb7dSCy Schubert ;; 1328f76bb7dSCy Schubert condrestart|try-restart) 1338f76bb7dSCy Schubert rh_status_q || exit 0 1348f76bb7dSCy Schubert restart 1358f76bb7dSCy Schubert ;; 1368f76bb7dSCy Schubert *) 1378f76bb7dSCy Schubert echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}" 1388f76bb7dSCy Schubert exit 2 1398f76bb7dSCy Schubertesac 1408f76bb7dSCy Schubertexit $? 141