xref: /dragonfly/etc/rc.d/named (revision 1d1731fa)
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.1 2003/07/24 06:35:37 dillon Exp $
6#
7
8# PROVIDE: named
9# REQUIRE: SERVERS
10# BEFORE:  DAEMON
11# KEYWORD: DragonFly FreeBSD NetBSD
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
22case ${OSTYPE} in
23DragonFly)
24	nuser=bind
25	ngroup=bind
26	;;
27FreeBSD)
28	nuser=bind
29	ngroup=bind
30	;;
31NetBSD)
32	nuser=named
33	ngroup=named
34	;;
35esac
36
37# If running in a chroot cage, ensure that the appropriate files
38# exist inside the cage, as well as helper symlinks into the cage
39# from outside.
40#
41# As this is called after the is_running and required_dir checks
42# are made in run_rc_command(), we can safely assume ${named_chrootdir}
43# exists and named isn't running at this point (unless forcestart
44# is used).
45#
46chroot_autoupdate()
47{
48	# If the named-xfer in the system is newer than the one in the
49	# chroot directory or if it (in the chrootdir) doesn't exist
50	# copy it over
51	#
52	if [ ! -x "${named_chrootdir}/usr/libexec/named-xfer" -o \
53	    "${named_chrootdir}/usr/libexec/named-xfer" -ot \
54	    /usr/libexec/named-xfer ]; then
55		rm -f "${named_chrootdir}/usr/libexec/named-xfer"
56		cp -p /usr/libexec/named-xfer "${named_chrootdir}/usr/libexec"
57	fi
58
59	# Copy /dev/null over, if neccessary. Preserve everything (perms,
60	# ownership, mod times).
61	#
62	if [ ! -c "${named_chrootdir}/dev/null" ]; then
63	rm -f "${named_chrootdir}/dev/null"
64		( cd /dev ; /bin/pax -rw -pe null "${named_chrootdir}/dev" )
65	fi
66
67	# Copy local timezone information if it's not up-to-date.
68	#
69	if [ -f /etc/localtime ]; then
70		cmp -s /etc/localtime "${named_chrootdir}/etc/localtime" || \
71		cp -p /etc/localtime "${named_chrootdir}/etc/localtime"
72	fi
73}
74
75# Make symlinks to the correct pid and ndc socket files
76#
77make_symlinks()
78{
79	ln -fs "${named_chrootdir}${named_pidfile}" ${named_pidfile}
80	ln -fs "${named_chrootdir}/var/run/ndc" /var/run/ndc
81
82}
83
84named_precmd()
85{
86	case ${OSTYPE} in
87	DragonFly)
88		! checkyesno named_rcng && return 0
89		# Is the user using a sandbox?
90		if [ -z "$named_chrootdir" ]; then
91			rc_flags="-u $nuser -g $ngroup $rc_flags"
92			return 0
93		fi
94		# Do the following checks only if the user wants them done
95		checkyesno named_chroot_autoupdate && chroot_autoupdate
96		;;
97	FreeBSD)
98		! checkyesno named_rcng && return 0
99		# Is the user using a sandbox?
100		if [ -z "$named_chrootdir" ]; then
101			rc_flags="-u $nuser -g $ngroup $rc_flags"
102			return 0
103		fi
104
105		# Do the following checks only if the user wants them done
106		checkyesno named_chroot_autoupdate && chroot_autoupdate
107		;;
108	NetBSD)
109		chroot_autoupdate
110		;;
111	esac
112
113	case ${OSTYPE} in
114	DragonFly)
115		# Make the symlinks only if the user wants them done.
116                checkyesno named_symlink_enable && make_symlinks
117                ;;
118	FreeBSD)
119		# Make the symlinks only if the user wants them done.
120		checkyesno named_symlink_enable && make_symlinks
121		;;
122	NetBSD)
123		make_symlinks
124		;;
125	esac
126
127	#       Change run_rc_commands()'s internal copy of $named_flags
128	#
129	case ${OSTYPE} in
130	DragonFly)
131		! checkyesno named_rcng && return
132		;;
133	FreeBSD)
134		! checkyesno named_rcng && return
135		;;
136	esac
137	rc_flags="-u $nuser -g $ngroup -t ${named_chrootdir} $rc_flags"
138}
139
140load_rc_config $name
141# The following variable requires that rc.conf be loaded first
142#
143required_dirs="$named_chrootdir"	# if it is set, it must exist
144pidfile="${named_pidfile:-/var/run/${name}/pid}"
145
146run_rc_command "$1"
147