]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - etc/rc.d/named
This commit was generated by cvs2svn to compensate for changes in r147824,
[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 -shf ${named_chrootdir}/etc/namedb /etc/namedb
56
57         fi
58
59         # Mount a devfs in the chroot directory if needed
60         #
61         umount ${named_chrootdir}/dev 2>/dev/null
62         devfs_domount ${named_chrootdir}/dev devfsrules_hide_all
63         devfs -m ${named_chrootdir}/dev rule apply path null unhide
64         devfs -m ${named_chrootdir}/dev rule apply path random unhide
65
66         # Copy local timezone information if it is not up to date.
67         #
68         if [ -f /etc/localtime ]; then
69                 cmp -s /etc/localtime "${named_chrootdir}/etc/localtime" || \
70                 cp -p /etc/localtime "${named_chrootdir}/etc/localtime"
71         fi
72 }
73
74 # Make symlinks to the correct pid file
75 #
76 make_symlinks()
77 {
78         checkyesno named_symlink_enable &&
79         ln -fs "${named_chrootdir}${pidfile}" ${pidfile}
80 }
81
82 named_poststop()
83 {
84         if [ -n "${named_chrootdir}"  -a -c ${named_chrootdir}/dev/null ]; then
85                 umount ${named_chrootdir}/dev 2>/dev/null || true
86         fi
87 }
88
89 named_precmd()
90 {
91         local confgen_chroot
92
93         # Is the user using a sandbox?
94         #
95         if [ -n "$named_chrootdir" ]; then
96                 rc_flags="$rc_flags -t $named_chrootdir"
97                 confgen_chroot="-t${named_chrootdir} -u bind"
98                 checkyesno named_chroot_autoupdate && chroot_autoupdate
99         else
100                 named_symlink_enable=NO
101         fi
102
103         # Create an rndc.key file for the user if none exists
104         #
105         if [ ! -f "${named_chrootdir}/etc/namedb/rndc.key" -a \
106             ! -f "${named_chrootdir}/etc/namedb/rndc.conf" ]; then
107                 rndc-confgen -a -b256 ${confgen_chroot}
108         fi
109 }
110
111 load_rc_config $name
112 # The following variable requires that rc.conf be loaded first
113 #
114 required_dirs="$named_chrootdir"        # if it is set, it must exist
115 pidfile="${named_pidfile:-/var/run/${name}/pid}"
116
117 run_rc_command "$1"