Home | History | Annotate | Line # | Download | only in contrib
      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: $named 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/init.d/functions
     23 
     24 exec="/usr/sbin/unbound"
     25 prog="unbound"
     26 config="/etc/unbound/unbound.conf"
     27 pidfile="/var/unbound/unbound.pid"
     28 rootdir="/var/unbound"
     29 
     30 [ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog
     31 
     32 lockfile=/var/lock/subsys/$prog
     33 
     34 start() {
     35     [ -x $exec ] || exit 5
     36     [ -f $config ] || exit 6
     37     echo -n $"Starting $prog: "
     38 
     39     # setup root jail
     40     if [ -s /etc/localtime ]; then 
     41 	[ -d ${rootdir}/etc ] || mkdir -p ${rootdir}/etc ;
     42 	if [ ! -e ${rootdir}/etc/localtime ] || ! /usr/bin/cmp -s /etc/localtime ${rootdir}/etc/localtime; then
     43 	    cp -fp /etc/localtime ${rootdir}/etc/localtime
     44 	fi;
     45     fi;
     46     if [ -s /etc/resolv.conf ]; then
     47 	[ -d ${rootdir}/etc ] || mkdir -p ${rootdir}/etc ;
     48 	if [ ! -e ${rootdir}/etc/resolv.conf ] || ! /usr/bin/cmp -s /etc/resolv.conf ${rootdir}/etc/resolv.conf; then
     49 	    cp -fp /etc/resolv.conf ${rootdir}/etc/resolv.conf
     50 	fi;
     51     fi;
     52     if ! egrep -q '^/[^[:space:]]+[[:space:]]+'${rootdir}'/dev/log' /proc/mounts; then
     53 	[ -d ${rootdir}/dev ] || mkdir -p ${rootdir}/dev ;
     54 	[ -e ${rootdir}/dev/log ] || touch ${rootdir}/dev/log
     55 	mount --bind -n /dev/log ${rootdir}/dev/log >/dev/null 2>&1;
     56     fi;
     57     if ! egrep -q '^/[^[:space:]]+[[:space:]]+'${rootdir}'/dev/random' /proc/mounts; then
     58 	[ -d ${rootdir}/dev ] || mkdir -p ${rootdir}/dev ;
     59 	[ -e ${rootdir}/dev/random ] || touch ${rootdir}/dev/random
     60 	mount --bind -n /dev/random ${rootdir}/dev/random >/dev/null 2>&1;
     61     fi;
     62 
     63     # if not running, start it up here
     64     daemonize $exec
     65     retval=$?
     66     echo
     67     [ $retval -eq 0 ] && touch $lockfile
     68     return $retval
     69 }
     70 
     71 stop() {
     72     echo -n $"Stopping $prog: "
     73     # stop it here, often "killproc $prog"
     74     killproc $prog
     75     retval=$?
     76     echo
     77     [ $retval -eq 0 ] && rm -f $lockfile
     78     [ $retval -eq 0 ] && rm -f $pidfile
     79     if egrep -q '^/[^[:space:]]+[[:space:]]+'${rootdir}'/dev/log' /proc/mounts; then
     80 	umount ${rootdir}/dev/log >/dev/null 2>&1
     81     fi;
     82     if egrep -q '^/[^[:space:]]+[[:space:]]+'${rootdir}'/dev/random' /proc/mounts; then
     83 	umount ${rootdir}/dev/random >/dev/null 2>&1
     84     fi;
     85     return $retval
     86 }
     87 
     88 restart() {
     89     stop
     90     start
     91 }
     92 
     93 reload() {
     94     kill -HUP `cat $pidfile`
     95 }
     96 
     97 force_reload() {
     98     restart
     99 }
    100 
    101 rh_status() {
    102     # run checks to determine if the service is running or use generic status
    103     status $prog
    104 }
    105 
    106 rh_status_q() {
    107     rh_status -p $pidfile >/dev/null 2>&1
    108 }
    109 
    110 case "$1" in
    111     start)
    112         rh_status_q && exit 0
    113         $1
    114         ;;
    115     stop)
    116         rh_status_q || exit 0
    117         $1
    118         ;;
    119     restart)
    120         $1
    121         ;;
    122     reload)
    123         rh_status_q || exit 7
    124         $1
    125         ;;
    126     force-reload)
    127         force_reload
    128         ;;
    129     status)
    130         rh_status
    131         ;;
    132     condrestart|try-restart)
    133         rh_status_q || exit 0
    134         restart
    135         ;;
    136     *)
    137         echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
    138         exit 2
    139 esac
    140 exit $?
    141