Home | History | Annotate | Line # | Download | only in rc.d
named revision 1.18
      1 #!/bin/sh
      2 #
      3 # $NetBSD: named,v 1.18 2005/11/29 21:07:25 christos Exp $
      4 #
      5 
      6 # PROVIDE: named
      7 # REQUIRE: SERVERS
      8 # BEFORE:  DAEMON
      9 # KEYWORD: chrootdir
     10 
     11 $_rc_subr_loaded . /etc/rc.subr
     12 
     13 name="named"
     14 rcvar=$name
     15 command="/usr/sbin/${name}"
     16 pidfile="/var/run/${name}.pid"
     17 start_precmd="named_precmd"
     18 extra_commands="reload"
     19 required_dirs="$named_chrootdir"	# if it is set, it must exist
     20 
     21 named_migrate()
     22 {
     23 	local src=$1
     24 	local dst=$2$1
     25 	echo "Migrating $src to $dst"
     26 (
     27 	diff=false
     28 	cd $src
     29 	for f in $(find . -type f)
     30 	do
     31 		f=${f##./}
     32 		case $f in
     33 		*/*)
     34 			d=$dst$(dirname $f)
     35 			;;
     36 		*)	d=$dst
     37 			;;
     38 		esac
     39 		mkdir -p $d
     40 		if [ -r "$dst/$f" ]
     41 		then
     42 			if ! cmp $f $dst/$f; then
     43 				diff=true
     44 			fi
     45 		else
     46 			cp -p $f $dst/$f
     47 		fi
     48 	done
     49 	if $diff; then
     50 		echo "Cannot complete migration because files are different"
     51 		echo "Run 'diff -r $src $dst' resolve the differences"
     52 	else
     53 		rm -fr $src
     54 		ln -s $dst $src
     55 	fi
     56 )
     57 }
     58 
     59 named_precmd()
     60 {
     61 	if [ -z "$named_chrootdir" ]; then
     62 		return 0;
     63 	fi
     64 
     65 	# If running in a chroot cage, ensure that the appropriate files
     66 	# exist inside the cage, as well as helper symlinks into the cage 
     67 	# from outside.
     68 	#
     69 	# As this is called after the is_running and required_dir checks
     70 	# are made in run_rc_command(), we can safely assume ${named_chrootdir}
     71 	# exists and named isn't running at this point (unless forcestart
     72 	# is used).
     73 	#
     74 	case "$($command -v)" in
     75 	BIND*)	# 9 no group, named-xfer, or ndc
     76 		;;
     77 	named*)	# 4 and 8
     78 		rc_flags="-g named $rc_flags"
     79 		if [ ! -x "${named_chrootdir}/usr/libexec/named-xfer" -o \
     80 		    "${named_chrootdir}/usr/libexec/named-xfer" -ot \
     81 		    /usr/libexec/named-xfer ]; then
     82 			rm -f "${named_chrootdir}/usr/libexec/named-xfer"
     83 			cp -p /usr/libexec/named-xfer \
     84 			    "${named_chrootdir}/usr/libexec"
     85 		fi
     86 		ln -fs "${named_chrootdir}/var/run/ndc" /var/run/ndc
     87 		;;
     88 	esac
     89 
     90 	for i in null random
     91 	do
     92 		if [ ! -c "${named_chrootdir}/dev/$i" ]; then
     93 			rm -f "${named_chrootdir}/dev/$i"
     94 			(cd /dev && 
     95 			    /bin/pax -rw -pe "$i" "${named_chrootdir}/dev")
     96 		fi
     97 	done
     98 
     99 	if [ ! -h /etc/namedb ]; then
    100 		named_migrate /etc/namedb ${named_chrootdir}
    101 	fi
    102 	if [ \( -r /etc/named.conf \) -a \( ! -h /etc/named.conf \) -a \
    103 	     \( ! -r ${named_chrootdir}/etc/named.conf \) ]
    104 	then
    105 		mv /etc/named.conf ${named_chrootdir}/etc/named.conf
    106 		ln -s ${named_chrootdir}/etc/named.conf /etc/named.conf
    107 	fi
    108 	if [ \( ! -r ${named_chrootdir}/etc/named.conf \) -a \
    109 	    \( -r ${named_chrootdir}/etc/namedb/named.conf \) ]; then
    110 		ln -s namedb/named.conf ${named_chrootdir}/etc
    111 	fi
    112 
    113 	if [ -f /etc/localtime ]; then
    114 		cmp -s /etc/localtime "${named_chrootdir}/etc/localtime" || \
    115 		    cp -p /etc/localtime "${named_chrootdir}/etc/localtime"
    116 	fi
    117 	ln -fs "${named_chrootdir}${pidfile}" ${pidfile}
    118 
    119 	#	Change run_rc_commands()'s internal copy of $named_flags
    120 	#
    121 	rc_flags="-u named -t ${named_chrootdir} $rc_flags"
    122 }
    123 
    124 load_rc_config $name
    125 run_rc_command "$1"
    126