Home | History | Annotate | Line # | Download | only in rc.d
named revision 1.16
      1 #!/bin/sh
      2 #
      3 # $NetBSD: named,v 1.16 2005/07/17 16:30:57 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_precmd()
     22 {
     23 	if [ -z "$named_chrootdir" ]; then
     24 		return 0;
     25 	fi
     26 
     27 	# If running in a chroot cage, ensure that the appropriate files
     28 	# exist inside the cage, as well as helper symlinks into the cage 
     29 	# from outside.
     30 	#
     31 	# As this is called after the is_running and required_dir checks
     32 	# are made in run_rc_command(), we can safely assume ${named_chrootdir}
     33 	# exists and named isn't running at this point (unless forcestart
     34 	# is used).
     35 	#
     36 	case "$($command -v)" in
     37 	BIND*)	# 9 no group, named-xfer, or ndc
     38 		;;
     39 	named*)	# 4 and 8
     40 		rc_flags="-g named $rc_flags"
     41 		if [ ! -x "${named_chrootdir}/usr/libexec/named-xfer" -o \
     42 		    "${named_chrootdir}/usr/libexec/named-xfer" -ot \
     43 		    /usr/libexec/named-xfer ]; then
     44 			rm -f "${named_chrootdir}/usr/libexec/named-xfer"
     45 			cp -p /usr/libexec/named-xfer \
     46 			    "${named_chrootdir}/usr/libexec"
     47 		fi
     48 		ln -fs "${named_chrootdir}/var/run/ndc" /var/run/ndc
     49 		;;
     50 	esac
     51 
     52 	for i in null random
     53 	do
     54 		if [ ! -c "${named_chrootdir}/dev/$i" ]; then
     55 			rm -f "${named_chrootdir}/dev/$i"
     56 			(cd /dev && 
     57 			    /bin/pax -rw -pe "$i" "${named_chrootdir}/dev")
     58 		fi
     59 	done
     60 
     61 	if [ -d /etc/namedb ]; then
     62 		(cd /etc/namedb && for i in *; do
     63 			j=${named_chrootdir}/etc/namedb/$i
     64 			if [ ! -r $j ]; then
     65 				cp -rp $i $j
     66 			fi
     67 		done)
     68 	fi
     69 	if [ \( ! -r ${named_chrootdir}/etc/named.conf \) -a \
     70 	    \( -r ${named_chrootdir}/etc/namedb/named.conf \) ]; then
     71 		ln -s namedb/named.conf ${named_chrootdir}/etc
     72 	fi
     73 
     74 	if [ -f /etc/localtime ]; then
     75 		cmp -s /etc/localtime "${named_chrootdir}/etc/localtime" || \
     76 		    cp -p /etc/localtime "${named_chrootdir}/etc/localtime"
     77 	fi
     78 	ln -fs "${named_chrootdir}${pidfile}" ${pidfile}
     79 
     80 	#	Change run_rc_commands()'s internal copy of $named_flags
     81 	#
     82 	rc_flags="-u named -t ${named_chrootdir} $rc_flags"
     83 }
     84 
     85 load_rc_config $name
     86 run_rc_command "$1"
     87