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