home *** CD-ROM | disk | FTP | other *** search
/ chilidog.highland.cc.ks.us / chilidog.highland.cc.ks.us.zip / chilidog.highland.cc.ks.us / backup / bradford.20120305.etc.tar.gz / bradford.20120305.etc.tar / etc / init.d / named < prev    next >
Text File  |  2009-02-09  |  10KB  |  344 lines

  1. #! /bin/sh
  2. # Copyright (c) 1995-2004 SUSE Linux AG, Nuernberg, Germany
  3. # All rights reserved.
  4. #
  5. # Author: Lars Mueller <lmuelle@suse.de>
  6. #
  7. # /etc/init.d/named
  8. #   and its symbolic link
  9. # /usr/sbin/rcnamed
  10. #
  11. #    This program is free software; you can redistribute it and/or modify 
  12. #    it under the terms of the GNU General Public License as published by 
  13. #    the Free Software Foundation; either version 2 of the License, or 
  14. #    (at your option) any later version. 
  15. #    This program is distributed in the hope that it will be useful, 
  16. #    but WITHOUT ANY WARRANTY; without even the implied warranty of 
  17. #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
  18. #    GNU General Public License for more details. 
  19. #    You should have received a copy of the GNU General Public License 
  20. #    along with this program; if not, write to the Free Software 
  21. #    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  22. #
  23. ### BEGIN INIT INFO
  24. # Provides:          named
  25. # Required-Start:    $network $remote_fs $syslog
  26. # Required-Stop:     $network $remote_fs $syslog
  27. # Should-Start:      ldap
  28. # Default-Start:     3 5
  29. # Default-Stop:      0 1 2 6
  30. # Short-Description: Domain Name System (DNS) server, named
  31. # Description:       Berkeley Internet Name Domain (BIND) implementation of the
  32. #    Domain Name System (DNS) server named.
  33. ### END INIT INFO
  34.  
  35. . /etc/rc.status
  36. rc_reset
  37.  
  38. PATH="/sbin:/usr/sbin:/bin:/usr/bin:/bsc/services/named/sbin:/bsc/services/named/bin"
  39. SSCONFIG_FILE="/bsc/siteConfiguration/named.variables"
  40. NAMED_CONF="/bsc/siteConfiguration/named.conf"
  41.  
  42. if [ "$1" != "stop" ]; then
  43.     for configfile in ${SYSCONFIG_FILE} ${NAMED_CONF}; do
  44.         if [ ! -f ${configfile} ]; then
  45.             echo -n "Name server configuration file ${configfile} does not exist. "
  46.             # Tell the user this has skipped
  47.             rc_status -s
  48.             exit 6
  49.         fi
  50.     done
  51.     . $SSCONFIG_FILE
  52.     # Ensure to work always with absolut filenames.
  53.     temp_file_list=""
  54.     for configfile in ${NAMED_CONF_INCLUDE_FILES}; do
  55.         # prepend the default include directory if the filename is
  56.         # relative
  57.         test "${configfile:0:1}" = "/" || configfile="/etc/named.d/${configfile}"
  58.         temp_file_list="${temp_file_list} ${configfile}"
  59.     done
  60.     NAMED_CONF_INCLUDE_FILES=${temp_file_list}
  61.     # Add include files from named.conf.
  62.     NAMED_CONF_INCLUDE_LINES=$( grep -e '^[[:space:]]*include' "${NAMED_CONF}" | cut -f 2 -d '"')
  63.     for file in ${NAMED_CONF_INCLUDE_LINES}; do
  64.         test "${file}" = "${NAMED_CONF_META_INCLUDE_FILE}" && continue
  65.         case "${NAMED_CONF_INCLUDE_FILES}" in
  66.             *${file}*) ;;
  67.             *) NAMED_CONF_INCLUDE_FILES="${NAMED_CONF_INCLUDE_FILES} ${file}" ;;
  68.         esac
  69.     done
  70. fi
  71.  
  72. if [ "${NAMED_RUN_CHROOTED}" = "yes" ]; then
  73.     CHROOT_PREFIX="/var/lib/named"
  74.     NAMED_ARGS="${NAMED_ARGS} -t ${CHROOT_PREFIX}"
  75.     NAMED_CHECKCONF_ARGS="-t ${CHROOT_PREFIX}"
  76. else
  77.     CHROOT_PREFIX=""
  78. fi
  79.  
  80. NAMED_BIN="/bsc/services/named/sbin/named"
  81. NAMED_CHECKCONF_BIN="/bsc/services/named/sbin/named-checkconf"
  82. NAMED_CONF_META_INCLUDE_FILE_SCRIPT="/bsc/services/named/bin/createNamedConfInclude"
  83. NAMED_PID="${CHROOT_PREFIX}/var/run/named/named.pid"
  84. RNDC_BIN="/bsc/services/named/sbin/rndc"
  85. NAMED_CONF_INCLUDE_FILE="/bsc/siteConfiguration/named.conf.include"
  86.  
  87. if [ ! -x ${NAMED_BIN} -a "$1" != "stop" ] ; then
  88.     echo -n "Name server, ${NAMED_BIN} not installed! "
  89.     # Tell the user this has skipped
  90.     rc_status -s
  91.     exit 5
  92. fi
  93.  
  94. # Check for NAMED_CONF_META_INCLUDE_FILE or set it to our default if we use
  95. # the NAMED_CONF_META_INCLUDE_FILE_SCRIPT script.
  96. #if [ -z "${NAMED_CONF_META_INCLUDE_FILE}" ]; then
  97. #    BASENAME_NAMED_CONF_META_INCLUDE_FILE_SCRIPT=$( basename ${NAMED_CONF_META_INCLUDE_FILE_SCRIPT})
  98. #    for script in ${NAMED_INITIALIZE_SCRIPTS}; do
  99. #        if [ "${script}" = "${BASENAME_NAMED_CONF_META_INCLUDE_FILE_SCRIPT}" -o \
  100. #        "${script}" = "${NAMED_CONF_META_INCLUDE_FILE_SCRIPT}" ]; then
  101. #            NAMED_CONF_META_INCLUDE_FILE=$NAMED_CONF_INCLUDE_FILE
  102. #            break
  103. #        fi
  104. #    done
  105. #fi
  106.  
  107. function warnMessage()
  108. {
  109.     tput bold
  110.     echo -en "\nWarning: "
  111.     tput sgr0
  112.     echo -e "$1 "
  113. }
  114.  
  115. function initializeNamed
  116. {
  117.     rc=0
  118. #    test "${initializeNamedCalled}" = "yes" && return
  119. #    for script in ${NAMED_INITIALIZE_SCRIPTS}; do
  120. #        test "${script:0:1}" = "/" || script="/usr/share/bind/${script}"
  121. #        ${script}
  122. #        test $? -ne 0 && rc=$?
  123. #    done
  124.     # We want to start each script one time only
  125. #    export initializeNamedCalled="yes"
  126.     return ${rc}
  127. }
  128.  
  129. # Create destination directory in the chroot.
  130. function makeDestDir
  131. {
  132.     if [ ! -d "${CHROOT_PREFIX}/${configfile%/*}" ]; then
  133.         umask 0022
  134.         mkdir -p "${CHROOT_PREFIX}/${configfile%/*}"
  135.     fi
  136. }
  137.  
  138. # Check if all needed configuration files exist and copy these files relativly
  139. # to the chroot directory if 'named' runs chrooted.
  140. function checkAndCopyConfigFiles
  141. {
  142.     test "${checkAndCopyConfigFilesCalled}" = "yes" && return
  143.     # check for /etc/rndc.key
  144.     if [ ! -f /etc/rndc.key ]; then
  145.         warnMessage "File /etc/rndc.key not found. Creating it."
  146.         /usr/sbin/rndc-confgen -a -b 512 -r /dev/urandom
  147.         chmod 0640 /etc/rndc.key
  148.         chown root:named /etc/rndc.key
  149.     fi
  150.     # Handle all include files.
  151.     #for configfile in "${NAMED_CONF_META_INCLUDE_FILE}" ${NAMED_CONF_INCLUDE_FILES}; do
  152.     for configfile in ${NAMED_CONF_INCLUDE_FILES}; do
  153.         if [ ! -f "${configfile}" ]; then
  154.             case "${configfile}" in
  155.                 "${NAMED_CONF_META_INCLUDE_FILE}")
  156.                     warnMessage "File, ${configfile} not found.  Creating it."
  157.                     initializeNamed
  158.                     ;;
  159.                 *)
  160.                     test -z "${NAMED_CONF_META_INCLUDE_FILE}" && continue
  161.                     grep -qe "^[[:space:]]*include[[:space:]]*\"${configfile}\"" "${NAMED_CONF_META_INCLUDE_FILE}" && \
  162.                         initializeNamed || \
  163.                         warnMessage "File, ${configfile} not found.  1Skipping.\nPlease check the setting of NAMED_CONF_INCLUDE_FILES in /etc/sysconfig/named."
  164.                     continue
  165.                     ;;
  166.             esac
  167.         fi
  168.         if [ "${NAMED_RUN_CHROOTED}" = "yes" ]; then
  169.             makeDestDir
  170.             rm -f ${CHROOT_PREFIX}/${configfile}
  171.             cp -a -L ${configfile} ${CHROOT_PREFIX}/${configfile%/*}
  172.         fi
  173.     done
  174.     # Handle known configuration files.
  175.     if [ "${NAMED_RUN_CHROOTED}" = "yes" ]; then
  176.         for configfile in ${NAMED_CONF} /etc/{localtime,rndc.key}; do
  177.             if [ ! -e ${configfile} ]; then
  178.                 warnMessage "File ${configfile} not found. 2Skipping."
  179.                 continue
  180.             fi
  181.             makeDestDir
  182.             rm -f ${CHROOT_PREFIX}/${configfile}
  183.  
  184.             cp -a -L ${configfile} ${CHROOT_PREFIX}/${configfile%/*}
  185.         done
  186.     fi
  187.  
  188.     # This is a Bradford specific change, related to the special directory
  189.     # structure that Bradford uses and the inflexible way that named-checkconf
  190.     # performs its checks.
  191.     (cd ${CHROOT_PREFIX}/etc ; ln -fs ../bsc/siteConfiguration/named.conf .)
  192.     (cd ${CHROOT_PREFIX}/etc ; ln -fs ../bsc/siteConfiguration/named.conf.include .)
  193.     # END of Bradford specific change
  194.  
  195.     export checkAndCopyConfigFilesCalled="yes"
  196. }
  197.  
  198. # Check the syntax of our 'named' configuration.
  199. function namedCheckConf
  200. {
  201.     test "${namedConfChecked}" = "yes" && return
  202.     if ! ${NAMED_CHECKCONF_BIN} ${NAMED_CHECKCONF_ARGS} >/dev/null; then
  203.         checkAndCopyConfigFiles
  204.         if ! ${NAMED_CHECKCONF_BIN} ${NAMED_CHECKCONF_ARGS}; then
  205.             rc_status -s
  206.             rc_failed 6
  207.             rc_exit
  208.         fi
  209.     fi
  210.     export namedConfChecked="yes"
  211. }
  212.  
  213. case "$1" in
  214.     start)
  215.     echo -n "Starting name server BIND "
  216.     . $SSCONFIG_FILE
  217.     checkproc -p ${NAMED_PID} ${NAMED_BIN}
  218.     case $? in
  219.         0) echo -n "- Warning: named already running! " ;;
  220.         1) echo -n "- Warning: ${NAMED_PID} exists! " ;;
  221.     esac
  222.     checkAndCopyConfigFiles
  223.  
  224.     # 6-feb-209 kclark@bradford
  225.     # Hack to deal with the new kernel
  226.     /sbin/modprobe capability
  227.  
  228.     namedCheckConf
  229.     initializeNamed
  230.     startproc -p ${NAMED_PID} ${NAMED_BIN} ${NAMED_ARGS} -u named
  231. #    startproc -p ${NAMED_PID} ${NAMED_BIN} ${NAMED_ARGS} 
  232.     rc_status -v
  233.     ;;
  234.     stop)
  235.     echo -n "Shutting down name server BIND "
  236.     checkproc -p ${NAMED_PID} ${NAMED_BIN} || echo -n "- Warning: named not running! "
  237.     if ${RNDC_BIN} status &>/dev/null; then
  238.         ${RNDC_BIN} stop
  239.     else
  240.         killproc -p ${NAMED_PID} -TERM ${NAMED_BIN}
  241.     fi
  242.     rc=$?
  243.  
  244.     # let's wait, because
  245.     # 1) trying to start named before it has terminated can leave
  246.     #    us without a running named...
  247.     # 2) making sure that pending updates are written to zone files is good
  248.     #    before trying to modify them externally
  249.     info="no"; timeout=30; rc=0; startDate=$( date +%s)
  250.     while [ ${rc} -eq 0 ]; do
  251.         checkproc -p ${NAMED_PID} ${NAMED_BIN}
  252.         rc=$?
  253.         if [ ${rc} -ne 0 ]; then
  254.             test "${info}" = "yes" && rc_timer_off
  255.             break
  256.         elif [ ${info} = "no" ]; then
  257.             echo -n >&2 " waiting for named to shut down "
  258.             rc_timer_on ${timeout} 63
  259.             info="yes"
  260.         fi
  261.         if [ $(( $( date +%s) - ${startDate} )) -gt $timeout ]; then
  262.             echo -en >&2 "\nNamed still appears to be running after $timeout seconds, sending SIGTERM"
  263.             rc=1
  264.             killproc -p ${NAMED_PID} -TERM ${NAMED_BIN}
  265.         else
  266.             sleep 2
  267.         fi
  268.     done
  269.  
  270.     rc_status -v
  271.     ;;
  272.     try-restart|condrestart)
  273.     if test "$1" = "condrestart"; then
  274.         echo "${attn} Use try-restart ${done}(LSB)${attn} rather than condrestart ${warn}(RH)${norm}"
  275.     fi
  276.     namedCheckConf
  277.     $0 status
  278.     if test $? = 0; then
  279.         $0 restart
  280.     else
  281.         rc_reset
  282.     fi
  283.     rc_status
  284.     ;;
  285.     restart)
  286.     namedCheckConf
  287.     # Some of the scripts need a running named.
  288.     $0 status >/dev/null && initializeNamed
  289.     $0 stop
  290.     $0 start
  291.     rc_status
  292.     ;;
  293.     force-reload|reload)
  294.     echo -n "Reloading name server BIND "
  295.     checkproc -p ${NAMED_PID} ${NAMED_BIN} || echo "- Warning: named not running! "
  296.     rc=$?
  297.     if [ ${rc} -ne 0 ]; then
  298.         echo "- Warning: named not running! "
  299.     else
  300.         checkAndCopyConfigFiles
  301.         namedCheckConf
  302.         initializeNamed
  303.         ${RNDC_BIN} status &>/dev/null
  304.         if [ $? -ne 0 ]; then
  305.             killproc -p ${NAMED_PID} -HUP ${NAMED_BIN}
  306.         else
  307.             ${RNDC_BIN} reload
  308.         fi
  309.         rc=$?
  310.     fi
  311.     ( exit ${rc} )
  312.     rc_status -v
  313.     ;;
  314.     status)
  315.     echo -n "Checking for nameserver BIND "
  316.     checkproc -p ${NAMED_PID} ${NAMED_BIN}
  317.     if [ $? -ne 0 ]; then
  318.         false    
  319.     else
  320.         test "${RNDC_BIN}" && echo && ${RNDC_BIN} status && echo -en "${esc}[1A"
  321.         true
  322.     fi
  323.     rc_status -v
  324.     ;;
  325.     probe)
  326.     rc=0
  327.     for configfile in ${NAMED_CONF} /etc/{localtime,rndc.key} "${NAMED_CONF_META_INCLUDE_FILE}" ${NAMED_CONF_INCLUDE_FILES}; do
  328.         if [ "${configfile}" -nt ${NAMED_PID} ]; then
  329.             rc=1
  330.             break
  331.         fi
  332.     done
  333.     test ${rc} -ne 0 && echo reload
  334.     ;;
  335.     *)
  336.     echo "Usage: $0 {start|stop|status|try-restart|restart|force-reload|reload|probe}"
  337.     exit 1
  338.     ;;
  339. esac
  340. rc_exit
  341.  
  342.