| 1 |
#!/bin/sh |
| 2 |
# |
| 3 |
# unbound This shell script takes care of starting and stopping |
| 4 |
# unbound (DNS server). |
| 5 |
# |
| 6 |
# chkconfig: - 14 86 |
| 7 |
# description: unbound is a Domain Name Server (DNS) \ |
| 8 |
# that is used to resolve host names to IP addresses. |
| 9 |
|
| 10 |
### BEGIN INIT INFO |
| 11 |
# Provides: unbound |
| 12 |
# Required-Start: $network $local_fs |
| 13 |
# Required-Stop: $network $local_fs |
| 14 |
# Should-Start: $syslog |
| 15 |
# Should-Stop: $syslog |
| 16 |
# Short-Description: unbound recursive Domain Name Server. |
| 17 |
# Description: unbound is a Domain Name Server (DNS) |
| 18 |
# that is used to resolve host names to IP addresses. |
| 19 |
### END INIT INFO |
| 20 |
|
| 21 |
# Source function library. |
| 22 |
. /etc/rc.d/init.d/functions |
| 23 |
|
| 24 |
exec="/usr/sbin/unbound" |
| 25 |
config="/var/lib/unbound/unbound.conf" |
| 26 |
rootdir="/var/lib/unbound" |
| 27 |
pidfile="/var/run/unbound/unbound.pid" |
| 28 |
|
| 29 |
[ -e /etc/sysconfig/unbound ] && . /etc/sysconfig/unbound |
| 30 |
|
| 31 |
lockfile=/var/lock/subsys/unbound |
| 32 |
|
| 33 |
start() { |
| 34 |
[ -x $exec ] || exit 5 |
| 35 |
[ -f $config ] || exit 6 |
| 36 |
echo -n $"Starting unbound: " |
| 37 |
|
| 38 |
if [ ! -e ${rootdir}/etc/resolv.conf ] || /usr/bin/cmp -s /etc/resolv.conf ${rootdir}/etc/resolv.conf; then |
| 39 |
cp -fp /etc/resolv.conf ${rootdir}/etc/resolv.conf |
| 40 |
fi; |
| 41 |
if [ ! -e ${rootdir}/etc/localtime ] || /usr/bin/cmp -s /etc/localtime ${rootdir}/etc/localtime; then |
| 42 |
cp -fp /etc/localtime ${rootdir}/etc/localtime |
| 43 |
fi; |
| 44 |
mount --bind -n /dev/log ${rootdir}/dev/log >/dev/null 2>&1; |
| 45 |
mount --bind -n /dev/urandom ${rootdir}/dev/urandom >/dev/null 2>&1; |
| 46 |
mount --bind -n /var/run/unbound ${rootdir}/var/run/unbound >/dev/null 2>&1; |
| 47 |
|
| 48 |
# if not running, start it up here |
| 49 |
daemon $exec |
| 50 |
retval=$? |
| 51 |
[ $retval -eq 0 ] && touch $lockfile |
| 52 |
echo |
| 53 |
} |
| 54 |
|
| 55 |
stop() { |
| 56 |
echo -n $"Stopping unbound: " |
| 57 |
# stop it here, often "killproc unbound" |
| 58 |
killproc -p $pidfile unbound |
| 59 |
retval=$? |
| 60 |
[ $retval -eq 0 ] && rm -f $lockfile |
| 61 |
[ $retval -eq 0 ] && rm -f $pidfile |
| 62 |
for mountfile in /dev/log /dev/urandom /etc/localtime /etc/resolv.conf /var/run/unbound |
| 63 |
do |
| 64 |
if egrep -q '^/[^[:space:]]+[[:space:]]+'${rootdir}''${mountfile}'' /proc/mounts; then |
| 65 |
umount ${rootdir}$mountfile >/dev/null 2>&1 |
| 66 |
fi; |
| 67 |
done |
| 68 |
echo |
| 69 |
} |
| 70 |
|
| 71 |
restart() { |
| 72 |
stop |
| 73 |
start |
| 74 |
} |
| 75 |
|
| 76 |
reload() { |
| 77 |
kill -HUP `cat $pidfile` |
| 78 |
} |
| 79 |
|
| 80 |
force_reload() { |
| 81 |
restart |
| 82 |
} |
| 83 |
|
| 84 |
rh_status() { |
| 85 |
# run checks to determine if the service is running or use generic status |
| 86 |
status -p $pidfile unbound |
| 87 |
} |
| 88 |
|
| 89 |
rh_status_q() { |
| 90 |
rh_status -p $pidfile >/dev/null 2>&1 |
| 91 |
} |
| 92 |
|
| 93 |
case "$1" in |
| 94 |
start) |
| 95 |
start |
| 96 |
;; |
| 97 |
stop) |
| 98 |
stop |
| 99 |
;; |
| 100 |
restart) |
| 101 |
restart |
| 102 |
;; |
| 103 |
reload) |
| 104 |
reload |
| 105 |
;; |
| 106 |
force-reload) |
| 107 |
force_reload |
| 108 |
;; |
| 109 |
status) |
| 110 |
rh_status |
| 111 |
;; |
| 112 |
condrestart|try-restart) |
| 113 |
rh_status_q || exit 0 |
| 114 |
restart |
| 115 |
;; |
| 116 |
*) |
| 117 |
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}" |
| 118 |
exit 2 |
| 119 |
esac |
| 120 |
exit $? |