3 # $NetBSD: named,v 1.25 2014/07/13 22:06:56 tls Exp $
7 # REQUIRE: NETWORKING mountcritremote syslogd
11 $_rc_subr_loaded .
/etc
/rc.subr
15 command="/usr/sbin/${name}"
16 pidfile
="/var/run/${name}/${name}.pid"
17 start_precmd
="named_precmd"
18 extra_commands
="reload"
19 required_dirs
="$named_chrootdir" # if it is set, it must exist
25 echo "Migrating $src to $dst"
30 for f
in $
(find .
-type f
)
38 chmod "$(stat -f "%p
" "$ds" |
39 sed -e 's/.*\([0-7][0-7][0-7][0-7]\)$/\1/g')" "$dd"
40 chown
"$(stat -f %u:%g "$ds")" "$dd"
47 if ! cmp "$f" "$dst/$f"; then
55 echo "Cannot complete migration because files are different"
56 echo "Run 'diff -r $src $dst' resolve the differences"
66 if [ ! -e "/etc/rndc.key" ]; then
67 echo "Generating rndc.key"
68 /usr
/sbin
/rndc-confgen
-a
71 if [ -z "$named_chrootdir" ]; then
72 if [ ! -d "/etc/namedb/keys" ]; then
73 mkdir
-m 775 "/etc/namedb/keys"
74 chown named
:named
"/etc/namedb/keys"
79 # If running in a chroot cage, ensure that the appropriate files
80 # exist inside the cage, as well as helper symlinks into the cage
83 # As this is called after the is_running and required_dir checks
84 # are made in run_rc_command(), we can safely assume ${named_chrootdir}
85 # exists and named isn't running at this point (unless forcestart
88 case "$($command -v)" in
89 BIND
*) # 9 no group, named-xfer, or ndc
92 rc_flags
="-g named $rc_flags"
93 if [ ! -x "${named_chrootdir}/usr/libexec/named-xfer" -o \
94 "${named_chrootdir}/usr/libexec/named-xfer" -ot \
95 /usr
/libexec
/named-xfer
]; then
96 rm -f "${named_chrootdir}/usr/libexec/named-xfer"
97 cp -p /usr
/libexec
/named-xfer \
98 "${named_chrootdir}/usr/libexec"
100 ln -fs "${named_chrootdir}/var/run/ndc" /var
/run
/ndc
104 for i
in null random urandom
; do
105 if [ ! -c "${named_chrootdir}/dev/$i" ]; then
106 rm -f "${named_chrootdir}/dev/$i"
108 /bin
/pax
-rw -pe "$i" "${named_chrootdir}/dev")
112 if [ ! -h /etc
/namedb
]; then
113 named_migrate
/etc
/namedb
${named_chrootdir}
116 for i
in named.conf rndc.key
; do
117 if [ \
( -r "/etc/$i" \
) -a \
( ! -h "/etc/$i" \
) -a \
118 \
( ! -r "${named_chrootdir}/etc/$i" \
) ]; then
119 mv "/etc/$i" "${named_chrootdir}/etc/$i"
120 ln -s "${named_chrootdir}/etc/$i" "/etc/$i"
124 if [ \
( ! -r ${named_chrootdir}/etc
/named.conf \
) -a \
125 \
( -r ${named_chrootdir}/etc
/namedb
/named.conf \
) ]; then
126 ln -s namedb
/named.conf
${named_chrootdir}/etc
129 if [ -f /etc
/localtime
]; then
130 cmp -s /etc
/localtime
"${named_chrootdir}/etc/localtime" || \
131 cp -p /etc
/localtime
"${named_chrootdir}/etc/localtime"
134 local piddir
="$(dirname "${pidfile}")"
135 mkdir
-p "${named_chrootdir}${piddir}" "${piddir}"
136 chmod 755 "${named_chrootdir}${piddir}" "${piddir}"
137 chown named
:named
"${named_chrootdir}${piddir}" "${piddir}"
138 ln -fs "${named_chrootdir}${pidfile}" "${pidfile}"
140 # Change run_rc_commands()'s internal copy of $named_flags
142 rc_flags
="-u named -t ${named_chrootdir} $rc_flags"