]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - etc/rc.d/named
This commit was generated by cvs2svn to compensate for changes in r151940,
[FreeBSD/FreeBSD.git] / etc / rc.d / named
1 #!/bin/sh
2 #
3 # $NetBSD: named,v 1.10 2002/03/22 04:33:59 thorpej Exp $
4 # $FreeBSD$
5 #
6
7 # PROVIDE: named
8 # REQUIRE: SERVERS cleanvar
9 # BEFORE:  DAEMON
10 # KEYWORD: shutdown
11
12 . /etc/rc.subr
13
14 name="named"
15 rcvar=`set_rcvar`
16 command="/usr/sbin/${name}"
17 start_precmd="named_precmd"
18 start_postcmd="make_symlinks"
19 stop_postcmd="named_poststop"
20 required_dirs="$named_chrootdir"        # if it is set, it must exist
21 extra_commands="reload"
22
23 # If running in a chroot cage, ensure that the appropriate files
24 # exist inside the cage, as well as helper symlinks into the cage
25 # from outside.
26 #
27 # As this is called after the is_running and required_dir checks
28 # are made in run_rc_command(), we can safely assume ${named_chrootdir}
29 # exists and named isn't running at this point (unless forcestart
30 # is used).
31 #
32 chroot_autoupdate()
33 {
34         # Create (or update) the chroot directory structure
35         #
36         if [ -f /etc/mtree/BIND.chroot.dist ]; then
37                 mtree -deU -f /etc/mtree/BIND.chroot.dist \
38                     -p ${named_chrootdir}
39         else
40                 warn "/etc/mtree/BIND.chroot.dist missing,"
41                 warn "chroot directory structure not updated"
42         fi
43
44         # Create /etc/namedb symlink
45         #
46         if [ ! -L /etc/namedb ]; then
47                 if [ -d /etc/namedb ]; then
48                         warn "named chroot: /etc/namedb is a directory!"
49                 elif [ -e /etc/namedb ]; then
50                         warn "named chroot: /etc/namedb exists!"
51                 else
52                         ln -s ${named_chrootdir}/etc/namedb /etc/namedb
53                 fi
54         else
55                 # Make sure it points to the right place.
56                 ln -shf ${named_chrootdir}/etc/namedb /etc/namedb
57
58         fi
59
60         # Mount a devfs in the chroot directory if needed
61         #
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
66
67         # Copy local timezone information if it is 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 file
76 #
77 make_symlinks()
78 {
79         checkyesno named_symlink_enable &&
80         ln -fs "${named_chrootdir}${pidfile}" ${pidfile}
81 }
82
83 named_poststop()
84 {
85         if [ -n "${named_chrootdir}"  -a -c ${named_chrootdir}/dev/null ]; then
86                 umount ${named_chrootdir}/dev 2>/dev/null || true
87         fi
88 }
89
90 named_precmd()
91 {
92         local confgen_chroot
93
94         # Is the user using a sandbox?
95         #
96         if [ -n "$named_chrootdir" ]; then
97                 rc_flags="$rc_flags -t $named_chrootdir"
98                 confgen_chroot="-t${named_chrootdir} -u bind"
99                 checkyesno named_chroot_autoupdate && chroot_autoupdate
100         else
101                 named_symlink_enable=NO
102         fi
103
104         # Create an rndc.key file for the user if none exists
105         #
106         if [ ! -f "${named_chrootdir}/etc/namedb/rndc.key" -a \
107             ! -f "${named_chrootdir}/etc/namedb/rndc.conf" ]; then
108                 rndc-confgen -a -b256 ${confgen_chroot}
109         fi
110 }
111
112 load_rc_config $name
113 # The following variable requires that rc.conf be loaded first
114 #
115 required_dirs="$named_chrootdir"        # if it is set, it must exist
116 pidfile="${named_pidfile:-/var/run/${name}/pid}"
117
118 run_rc_command "$1"