]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - etc/rc.d/named
This commit was generated by cvs2svn to compensate for changes in r142425,
[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 start_precmd="named_precmd"
17 start_postcmd="make_symlinks"
18 stop_postcmd="named_poststop"
19 required_dirs="$named_chrootdir"        # if it is set, it must exist
20 extra_commands="reload"
21
22 # If running in a chroot cage, ensure that the appropriate files
23 # exist inside the cage, as well as helper symlinks into the cage
24 # from outside.
25 #
26 # As this is called after the is_running and required_dir checks
27 # are made in run_rc_command(), we can safely assume ${named_chrootdir}
28 # exists and named isn't running at this point (unless forcestart
29 # is used).
30 #
31 chroot_autoupdate()
32 {
33         # Create (or update) the chroot directory structure
34         #
35         if [ -f /etc/mtree/BIND.chroot.dist ]; then
36                 mtree -deU -f /etc/mtree/BIND.chroot.dist \
37                     -p ${named_chrootdir}
38         else
39                 warn "/etc/mtree/BIND.chroot.dist missing,"
40                 warn "chroot directory structure not updated"
41         fi
42
43         # Create /etc/namedb symlink
44         #
45         if [ ! -L /etc/namedb ]; then
46                 if [ -d /etc/namedb ]; then
47                         warn "named chroot: /etc/namedb is a directory!"
48                 elif [ -e /etc/namedb ]; then
49                         warn "named chroot: /etc/namedb exists!"
50                 else
51                         ln -s ${named_chrootdir}/etc/namedb /etc/namedb
52                 fi
53         else
54                 # Make sure it points to the right place.
55                 ln -sf ${named_chrootdir}/etc/namedb /etc/namedb
56
57         fi
58
59         # Mount a devfs in the chroot directory if needed
60         #
61         if [ ! -c ${named_chrootdir}/dev/random -o \
62             ! -c ${named_chrootdir}/dev/null ]; then
63                 umount ${named_chrootdir}/dev 2>/dev/null
64                 mount_devfs devfs ${named_chrootdir}/dev
65         fi
66         devfs -m ${named_chrootdir}/dev rule apply hide
67         devfs -m ${named_chrootdir}/dev rule apply path null unhide
68         devfs -m ${named_chrootdir}/dev rule apply path random unhide
69
70         # Copy local timezone information if it is not up to date.
71         #
72         if [ -f /etc/localtime ]; then
73                 cmp -s /etc/localtime "${named_chrootdir}/etc/localtime" || \
74                 cp -p /etc/localtime "${named_chrootdir}/etc/localtime"
75         fi
76 }
77
78 # Make symlinks to the correct pid file
79 #
80 make_symlinks()
81 {
82         checkyesno named_symlink_enable &&
83         ln -fs "${named_chrootdir}${pidfile}" ${pidfile}
84 }
85
86 named_poststop()
87 {
88         if [ -n "${named_chrootdir}"  -a -c ${named_chrootdir}/dev/null ]; then
89                 umount ${named_chrootdir}/dev 2>/dev/null || true
90         fi
91 }
92
93 named_precmd()
94 {
95         local confgen_chroot
96
97         # Is the user using a sandbox?
98         #
99         if [ -n "$named_chrootdir" ]; then
100                 rc_flags="$rc_flags -t $named_chrootdir"
101                 confgen_chroot="-t${named_chrootdir} -u bind"
102                 checkyesno named_chroot_autoupdate && chroot_autoupdate
103         else
104                 named_symlink_enable=NO
105         fi
106
107         # Create an rndc.key file for the user if none exists
108         #
109         if [ ! -f "${named_chrootdir}/etc/namedb/rndc.key" -a \
110             ! -f "${named_chrootdir}/etc/namedb/rndc.conf" ]; then
111                 rndc-confgen -a -b256 ${confgen_chroot}
112         fi
113 }
114
115 load_rc_config $name
116 # The following variable requires that rc.conf be loaded first
117 #
118 required_dirs="$named_chrootdir"        # if it is set, it must exist
119 pidfile="${named_pidfile:-/var/run/${name}/pid}"
120
121 run_rc_command "$1"