7 # REQUIRE: SERVERS cleanvar
15 command="/usr/sbin/named"
16 extra_commands="reload"
18 start_precmd="named_precmd"
19 start_postcmd="make_symlinks"
20 reload_cmd="named_reload"
22 stop_postcmd="named_poststop"
24 # If running in a chroot cage, ensure that the appropriate files
25 # exist inside the cage, as well as helper symlinks into the cage
28 # As this is called after the is_running and required_dir checks
29 # are made in run_rc_command(), we can safely assume ${named_chrootdir}
30 # exists and named isn't running at this point (unless forcestart
35 # Create (or update) the chroot directory structure
37 if [ -r /etc/mtree/BIND.chroot.dist ]; then
38 mtree -deU -f /etc/mtree/BIND.chroot.dist \
41 warn "/etc/mtree/BIND.chroot.dist missing,"
42 warn "chroot directory structure not updated"
45 # Create /etc/namedb symlink
47 if [ ! -L /etc/namedb ]; then
48 if [ -d /etc/namedb ]; then
49 warn "named chroot: /etc/namedb is a directory!"
50 elif [ -e /etc/namedb ]; then
51 warn "named chroot: /etc/namedb exists!"
53 ln -s ${named_chrootdir}/etc/namedb /etc/namedb
56 # Make sure it points to the right place.
57 ln -shf ${named_chrootdir}/etc/namedb /etc/namedb
60 # Mount a devfs in the chroot directory if needed
62 umount ${named_chrootdir}/dev 2>/dev/null
63 devfs_domount ${named_chrootdir}/dev devfsrules_hide_all
64 devfs -m ${named_chrootdir}/dev rule apply path null unhide
65 devfs -m ${named_chrootdir}/dev rule apply path random unhide
67 # Copy local timezone information if it is not up to date.
69 if [ -r /etc/localtime ]; then
70 cmp -s /etc/localtime "${named_chrootdir}/etc/localtime" ||
71 cp -p /etc/localtime "${named_chrootdir}/etc/localtime"
75 # Make symlinks to the correct pid file
79 checkyesno named_symlink_enable &&
80 ln -fs "${named_chrootdir}${pidfile}" ${pidfile}
90 echo -n "Stopping named"
91 if rndc stop 2>/dev/null; then
94 echo -n ": rndc failed, trying killall: "
95 if killall named; then
103 if [ -n "${named_chrootdir}" -a -c ${named_chrootdir}/dev/null ]; then
104 umount ${named_chrootdir}/dev 2>/dev/null || true
110 # Is the user using a sandbox?
112 if [ -n "$named_chrootdir" ]; then
113 rc_flags="$rc_flags -t $named_chrootdir"
114 checkyesno named_chroot_autoupdate && chroot_autoupdate
116 named_symlink_enable=NO
119 # Create an rndc.key file for the user if none exists
121 if [ -s "${named_chrootdir}/etc/namedb/rndc.conf" ]; then
124 confgen_command="rndc-confgen -a -b256 -u $named_uid \
125 -c ${named_chrootdir}/etc/namedb/rndc.key"
126 if [ -s "${named_chrootdir}/etc/namedb/rndc.key" ]; then
127 if [ ! `stat -f%Su ${named_chrootdir}/etc/namedb/rndc.key` = \
137 # Updating the following variables requires that rc.conf be loaded first
139 required_dirs="$named_chrootdir" # if it is set, it must exist
140 pidfile="${named_pidfile:-/var/run/named/pid}"
141 command_args="-u ${named_uid:=root}"