xref: /netbsd/etc/rc.d/named (revision c4a72b64)
1#!/bin/sh
2#
3# $NetBSD: named,v 1.11 2002/06/18 14:35:38 lukem Exp $
4#
5
6# PROVIDE: named
7# REQUIRE: SERVERS
8# BEFORE:  DAEMON
9# KEYWORD: chrootdir
10
11. /etc/rc.subr
12
13name="named"
14rcvar=$name
15command="/usr/sbin/${name}"
16pidfile="/var/run/${name}.pid"
17start_precmd="named_precmd"
18extra_commands="reload"
19required_dirs="$named_chrootdir"	# if it is set, it must exist
20
21named_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
37	if [ ! -x "${named_chrootdir}/usr/libexec/named-xfer" -o \
38	    "${named_chrootdir}/usr/libexec/named-xfer" -ot \
39	    /usr/libexec/named-xfer ]; then
40		rm -f "${named_chrootdir}/usr/libexec/named-xfer"
41		cp -p /usr/libexec/named-xfer "${named_chrootdir}/usr/libexec"
42	fi
43	if [ ! -c "${named_chrootdir}/dev/null" ]; then
44		rm -f "${named_chrootdir}/dev/null"
45		( cd /dev ; /bin/pax -rw -pe null "${named_chrootdir}/dev" )
46	fi
47	if [ -f /etc/localtime ]; then
48		cmp -s /etc/localtime "${named_chrootdir}/etc/localtime" || \
49		    cp -p /etc/localtime "${named_chrootdir}/etc/localtime"
50	fi
51	ln -fs "${named_chrootdir}/var/run/named.pid" /var/run/named.pid
52	ln -fs "${named_chrootdir}/var/run/ndc" /var/run/ndc
53
54	#	Change run_rc_commands()'s internal copy of $named_flags
55	#
56	rc_flags="-u named -g named -t ${named_chrootdir} $rc_flags"
57}
58
59load_rc_config $name
60run_rc_command "$1"
61