xref: /dragonfly/etc/rc.d/named (revision 1ab20d67)
1#!/bin/sh
2#
3# $NetBSD: named,v 1.10 2002/03/22 04:33:59 thorpej Exp $
4# $FreeBSD: src/etc/rc.d/named,v 1.6 2003/01/12 04:53:54 mtm Exp $
5# $DragonFly: src/etc/rc.d/named,v 1.3 2004/03/26 13:32:27 drhodus Exp $
6#
7
8# PROVIDE: named
9# REQUIRE: SERVERS
10# BEFORE:  DAEMON
11# KEYWORD: DragonFly
12
13. /etc/rc.subr
14
15name="named"
16rcvar=`set_rcvar`
17command="/usr/sbin/${name}"
18start_precmd="named_precmd"
19required_dirs="$named_chrootdir"	# if it is set, it must exist
20extra_commands="reload"
21
22nuser=bind
23ngroup=bind
24
25# If running in a chroot cage, ensure that the appropriate files
26# exist inside the cage, as well as helper symlinks into the cage
27# from outside.
28#
29# As this is called after the is_running and required_dir checks
30# are made in run_rc_command(), we can safely assume ${named_chrootdir}
31# exists and named isn't running at this point (unless forcestart
32# is used).
33#
34chroot_autoupdate()
35{
36	# If the named-xfer in the system is newer than the one in the
37	# chroot directory or if it (in the chrootdir) doesn't exist
38	# copy it over
39	#
40	if [ ! -x "${named_chrootdir}/usr/libexec/named-xfer" -o \
41	    "${named_chrootdir}/usr/libexec/named-xfer" -ot \
42	    /usr/libexec/named-xfer ]; then
43		rm -f "${named_chrootdir}/usr/libexec/named-xfer"
44		cp -p /usr/libexec/named-xfer "${named_chrootdir}/usr/libexec"
45	fi
46
47	# Copy /dev/null over, if neccessary. Preserve everything (perms,
48	# ownership, mod times).
49	#
50	if [ ! -c "${named_chrootdir}/dev/null" ]; then
51	rm -f "${named_chrootdir}/dev/null"
52		( cd /dev ; /bin/pax -rw -pe null "${named_chrootdir}/dev" )
53	fi
54
55	# Copy local timezone information if it's not up-to-date.
56	#
57	if [ -f /etc/localtime ]; then
58		cmp -s /etc/localtime "${named_chrootdir}/etc/localtime" || \
59		cp -p /etc/localtime "${named_chrootdir}/etc/localtime"
60	fi
61}
62
63# Make symlinks to the correct pid and ndc socket files
64#
65make_symlinks()
66{
67	ln -fs "${named_chrootdir}${named_pidfile}" ${named_pidfile}
68	ln -fs "${named_chrootdir}/var/run/ndc" /var/run/ndc
69
70}
71
72named_precmd()
73{
74	! checkyesno named_rcng && return 0
75	# Is the user using a sandbox?
76	if [ -z "$named_chrootdir" ]; then
77		rc_flags="-u $nuser -g $ngroup $rc_flags"
78		return 0
79	fi
80	# Do the following checks only if the user wants them done
81	checkyesno named_chroot_autoupdate && chroot_autoupdate
82        checkyesno named_symlink_enable && make_symlinks
83
84	#       Change run_rc_commands()'s internal copy of $named_flags
85	#
86	! checkyesno named_rcng && return
87	rc_flags="-u $nuser -g $ngroup -t ${named_chrootdir} $rc_flags"
88}
89
90load_rc_config $name
91# The following variable requires that rc.conf be loaded first
92#
93required_dirs="$named_chrootdir"	# if it is set, it must exist
94pidfile="${named_pidfile:-/var/run/${name}.pid}"
95
96run_rc_command "$1"
97