]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - etc/rc.d/named
This commit was generated by cvs2svn to compensate for changes in r172958,
[FreeBSD/FreeBSD.git] / etc / rc.d / named
1 #!/bin/sh
2 #
3 # $FreeBSD$
4 #
5
6 # PROVIDE: named
7 # REQUIRE: SERVERS cleanvar
8 # KEYWORD: shutdown
9
10 . /etc/rc.subr
11
12 name="named"
13 rcvar=named_enable
14
15 command="/usr/sbin/named"
16 extra_commands="reload"
17
18 start_precmd="named_precmd"
19 start_postcmd="make_symlinks"
20 reload_cmd="named_reload"
21 stop_cmd="named_stop"
22 stop_postcmd="named_poststop"
23
24 # If running in a chroot cage, ensure that the appropriate files
25 # exist inside the cage, as well as helper symlinks into the cage
26 # from outside.
27 #
28 # As this is called after the is_running and required_dir checks
29 # are made in run_rc_command(), we can safely assume ${named_chrootdir}
30 # exists and named isn't running at this point (unless forcestart
31 # is used).
32 #
33 chroot_autoupdate()
34 {
35         # Create (or update) the chroot directory structure
36         #
37         if [ -r /etc/mtree/BIND.chroot.dist ]; then
38                 mtree -deU -f /etc/mtree/BIND.chroot.dist \
39                     -p ${named_chrootdir}
40         else
41                 warn "/etc/mtree/BIND.chroot.dist missing,"
42                 warn "chroot directory structure not updated"
43         fi
44
45         # Create /etc/namedb symlink
46         #
47         if [ ! -L /etc/namedb ]; then
48                 if [ -d /etc/namedb ]; then
49                         warn "named chroot: /etc/namedb is a directory!"
50                 elif [ -e /etc/namedb ]; then
51                         warn "named chroot: /etc/namedb exists!"
52                 else
53                         ln -s ${named_chrootdir}/etc/namedb /etc/namedb
54                 fi
55         else
56                 # Make sure it points to the right place.
57                 ln -shf ${named_chrootdir}/etc/namedb /etc/namedb
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 [ -r /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_reload()
84 {
85         ${command%/named}/rndc reload
86 }
87
88 named_stop()
89 {
90         # This duplicates an undesirably large amount of code from the stop
91         # routine in rc.subr in order to use rndc to shut down the process,
92         # and to give it a second chance in case rndc fails.
93         rc_pid=$(check_pidfile $pidfile $command)
94         if [ -z "$rc_pid" ]; then
95                 [ -n "$rc_fast" ] && return 0
96                 _run_rc_notrunning
97                 return 1
98         fi
99         echo 'Stopping named.'
100         if ${command%/named}/rndc stop 2>/dev/null; then
101                 wait_for_pids $rc_pid
102         else
103                 echo -n 'rndc failed, trying kill: '
104                 kill -TERM $rc_pid
105                 wait_for_pids $rc_pid
106         fi
107 }
108
109 named_poststop()
110 {
111         if [ -n "${named_chrootdir}" -a -c ${named_chrootdir}/dev/null ]; then
112                 umount ${named_chrootdir}/dev 2>/dev/null || true
113         fi
114 }
115
116 named_precmd()
117 {
118         # Is the user using a sandbox?
119         #
120         if [ -n "$named_chrootdir" ]; then
121                 rc_flags="$rc_flags -t $named_chrootdir"
122                 checkyesno named_chroot_autoupdate && chroot_autoupdate
123         else
124                 named_symlink_enable=NO
125         fi
126
127         # Create an rndc.key file for the user if none exists
128         #
129         if [ -s "${named_chrootdir}/etc/namedb/rndc.conf" ]; then
130                 return 0
131         fi
132         confgen_command="${command%/named}/rndc-confgen -a -b256 -u $named_uid \
133             -c ${named_chrootdir}/etc/namedb/rndc.key"
134         if [ -s "${named_chrootdir}/etc/namedb/rndc.key" ]; then
135                 case `stat -f%Su ${named_chrootdir}/etc/namedb/rndc.key` in
136                 root|$named_uid) ;;
137                 *) $confgen_command ;;
138                 esac
139         else
140                 $confgen_command
141         fi
142 }
143
144 load_rc_config $name
145 # Updating the following variables requires that rc.conf be loaded first
146 #
147 required_dirs="$named_chrootdir"        # if it is set, it must exist
148 pidfile="${named_pidfile:-/var/run/named/pid}"
149 command_args="-u ${named_uid:=root}"
150
151 run_rc_command "$1"