Sync usage with man page.
[netbsd-mini2440.git] / etc / rc.d / named
blob8a600465ab8dc25e2ee0beba3fba2814e5720262
1 #!/bin/sh
3 # $NetBSD: named,v 1.21 2009/04/25 15:46:19 christos Exp $
6 # PROVIDE: named
7 # REQUIRE: NETWORKING mountcritremote syslogd
8 # BEFORE: DAEMON
9 # KEYWORD: chrootdir
11 $_rc_subr_loaded . /etc/rc.subr
13 name="named"
14 rcvar=$name
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
21 named_migrate()
23 local src=$1
24 local dst=$2$1
25 echo "Migrating $src to $dst"
27 diff=false
28 cd $src
29 for f in $(find . -type f)
31 f=${f##./}
32 case $f in
33 */*)
34 d=$dst/$(dirname $f)
36 *) d=$dst
38 esac
39 mkdir -p $d
40 if [ -r "$dst/$f" ]
41 then
42 if ! cmp $f $dst/$f; then
43 diff=true
45 else
46 cp -p $f $dst/$f
48 done
49 if $diff; then
50 echo "Cannot complete migration because files are different"
51 echo "Run 'diff -r $src $dst' resolve the differences"
52 else
53 rm -fr $src
54 ln -s $dst $src
59 named_precmd()
61 if [ -z "$named_chrootdir" ]; then
62 return 0;
65 # If running in a chroot cage, ensure that the appropriate files
66 # exist inside the cage, as well as helper symlinks into the cage
67 # from outside.
69 # As this is called after the is_running and required_dir checks
70 # are made in run_rc_command(), we can safely assume ${named_chrootdir}
71 # exists and named isn't running at this point (unless forcestart
72 # is used).
74 case "$($command -v)" in
75 BIND*) # 9 no group, named-xfer, or ndc
77 named*) # 4 and 8
78 rc_flags="-g named $rc_flags"
79 if [ ! -x "${named_chrootdir}/usr/libexec/named-xfer" -o \
80 "${named_chrootdir}/usr/libexec/named-xfer" -ot \
81 /usr/libexec/named-xfer ]; then
82 rm -f "${named_chrootdir}/usr/libexec/named-xfer"
83 cp -p /usr/libexec/named-xfer \
84 "${named_chrootdir}/usr/libexec"
86 ln -fs "${named_chrootdir}/var/run/ndc" /var/run/ndc
88 esac
90 for i in null random
92 if [ ! -c "${named_chrootdir}/dev/$i" ]; then
93 rm -f "${named_chrootdir}/dev/$i"
94 (cd /dev &&
95 /bin/pax -rw -pe "$i" "${named_chrootdir}/dev")
97 done
99 if [ ! -h /etc/namedb ]; then
100 named_migrate /etc/namedb ${named_chrootdir}
102 if [ \( -r /etc/named.conf \) -a \( ! -h /etc/named.conf \) -a \
103 \( ! -r ${named_chrootdir}/etc/named.conf \) ]
104 then
105 mv /etc/named.conf ${named_chrootdir}/etc/named.conf
106 ln -s ${named_chrootdir}/etc/named.conf /etc/named.conf
108 if [ \( ! -r ${named_chrootdir}/etc/named.conf \) -a \
109 \( -r ${named_chrootdir}/etc/namedb/named.conf \) ]; then
110 ln -s namedb/named.conf ${named_chrootdir}/etc
113 if [ -f /etc/localtime ]; then
114 cmp -s /etc/localtime "${named_chrootdir}/etc/localtime" || \
115 cp -p /etc/localtime "${named_chrootdir}/etc/localtime"
118 local piddir="$(dirname "${pidfile}")"
119 mkdir -p "${named_chrootdir}${piddir}" "${piddir}"
120 chmod 755 "${named_chrootdir}${piddir}" "${piddir}"
121 chown named:named "${named_chrootdir}${piddir}" "${piddir}"
122 ln -fs "${named_chrootdir}${pidfile}" "${pidfile}"
124 # Change run_rc_commands()'s internal copy of $named_flags
126 rc_flags="-u named -t ${named_chrootdir} $rc_flags"
129 load_rc_config $name
130 run_rc_command "$1"