etc/services - sync with NetBSD-8
[minix.git] / etc / rc.d / named
blobe84d91099479b00f03205f70ec8f10fc296dc70b
1 #!/bin/sh
3 # $NetBSD: named,v 1.25 2014/07/13 22:06:56 tls 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 mkdir -p "$dst"
30 for f in $(find . -type f)
32 f="${f##./}"
33 case "$f" in
34 */*)
35 ds="$(dirname "$f")"
36 dd="$dst/$ds"
37 mkdir -p "$dd"
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"
44 esac
45 if [ -r "$dst/$f" ]
46 then
47 if ! cmp "$f" "$dst/$f"; then
48 diff=true
50 else
51 cp -p "$f" "$dst/$f"
53 done
54 if $diff; then
55 echo "Cannot complete migration because files are different"
56 echo "Run 'diff -r $src $dst' resolve the differences"
57 else
58 rm -fr "$src"
59 ln -s "$dst" "$src"
64 named_precmd()
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"
76 return 0;
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
81 # from outside.
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
86 # is used).
88 case "$($command -v)" in
89 BIND*) # 9 no group, named-xfer, or ndc
91 named*) # 4 and 8
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
102 esac
104 for i in null random urandom; do
105 if [ ! -c "${named_chrootdir}/dev/$i" ]; then
106 rm -f "${named_chrootdir}/dev/$i"
107 (cd /dev &&
108 /bin/pax -rw -pe "$i" "${named_chrootdir}/dev")
110 done
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"
122 done
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"
145 load_rc_config $name
146 run_rc_command "$1"