Debian Codegraph @

support/init.d.examples/named.in

raw
1 #!@SBINDIR@/openrc-run
2 # Copyright (c) 2007-2015 The OpenRC Authors.
3 # See the Authors file at the top-level directory of this distribution and
4 # https://github.com/OpenRC/openrc/blob/HEAD/AUTHORS
5 #
6 # This file is part of OpenRC. It is subject to the license terms in
7 # the LICENSE file found in the top-level directory of this
8 # distribution and at https://github.com/OpenRC/openrc/blob/HEAD/LICENSE
9 # This file may not be copied, modified, propagated, or distributed
10 # except according to the terms contained in the LICENSE file.
11
12 command=/usr/sbin/named
13 command_args=$named_args
14 pidfile=/var/run/named.pid
15 name="Domain Name server"
16 extra_started_commands="reload"
17
18 namedb=/etc/namedb
19 uid=named
20 case "$RC_UNAME" in
21 FreeBSD)
22 uid=bind
23 pidfile=/var/run/named/pid
24 ;;
25 Linux)
26 uid=bind
27 ;;
28 esac
29 : ${named_uid:=${uid}}
30
31 depend()
32 {
33 provide dns
34 need localmount
35 after bootmisc
36 }
37
38 start_pre()
39 {
40 if [ -n "$named_chroot" ]; then
41 # Create (or update) the chroot directory structure
42 if [ -r /etc/mtree/BIND.chroot.dist ]; then
43 mtree -deU -f /etc/mtree/BIND.chroot.dist -p "$named_chroot"
44 else
45 ewarn "/etc/mtree/BIND.chroot.dist missing,"
46 ewarn "chroot directory structure not updated"
47 fi
48
49 if [ ! -d "$named_chroot"/. ]; then
50 eerror "chroot directory $named_chroot missing"
51 exit 1
52 fi
53
54 # Create /etc/namedb symlink
55 if [ ! -L "$namedb" ]; then
56 if [ -d "$namedb" ]; then
57 ewarn "named chroot: $namedb is a directory!"
58 elif [ -e "$namedb" ]; then
59 ewarn "named chroot: $namedb exists!"
60 else
61 ln -s "$named_chroot$namedb" "$namedb"
62 fi
63 else
64 # Make sure it points to the right place.
65 ln -shf "$named_chroot$namedb" "$namedb"
66 fi
67
68 case "$RC_UNAME" in
69 *BSD|DragonFly)
70 # Mount a devfs in the chroot directory if needed
71 umount "$named_chroot"/dev 2>/dev/null
72 mount -t devfs dev "$named_chroot"/dev
73 devfs -m "$named_chroot"/dev \
74 ruleset devfsrules_hide_all
75 devfs -m "$named_chroot"/dev \
76 rule apply path null unhide
77 devfs -m "$named_chroot"/dev \
78 rule apply path random unhide
79 ;;
80 esac
81
82 # Copy local timezone information if it is not up to date.
83 if [ -r /etc/localtime ]; then
84 cmp -s /etc/localtime "$named_chroot/etc/localtime" ||
85 cp -p /etc/localtime "$named_chroot/etc/localtime"
86 fi
87
88 command_args="$command_args -t $named_chroot"
89
90 ln -fs "$named_chroot$pidfile" "$pidfile"
91 fi
92
93 if [ ! -s "$named_chroot$namedb/rndc.conf" ]; then
94 local confgen="${command%/named}/rndc-confgen -a -b256 -u $named_uid \
95 -c $named_chrootdir/etc/namedb/rndc.key"
96 if [ -s "$named_chroot$namedb/rndc.key" ]; then
97 local getuser="stat -f%Su"
98 [ "$RC_UNAME" = Linux ] && getuser="stat -c%U"
99 case $(${getuser} "$named_chroot$namedb"/rndc.key) in
100 root|"$named_uid");;
101 *) $confgen;;
102 esac
103 else
104 $confgen
105 fi
106 fi
107 }
108
109 reload()
110 {
111 rndc reload
112 }
113
114 stop_post()
115 {
116 if [ -n "$named_chroot" -a -c "$named_chroot"/dev/null ]; then
117 umount "$named_chroot"/dev 2>/dev/null || true
118 fi
119 }