1 |
idl0r 12/08/24 19:01:09 |
2 |
|
3 |
Added: named.init-r12 |
4 |
Log: |
5 |
Revision bump, fixes bug 429748. |
6 |
|
7 |
(Portage version: 2.2.0_alpha121/cvs/Linux x86_64) |
8 |
|
9 |
Revision Changes Path |
10 |
1.1 net-dns/bind/files/named.init-r12 |
11 |
|
12 |
file : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/net-dns/bind/files/named.init-r12?rev=1.1&view=markup |
13 |
plain: http://sources.gentoo.org/viewvc.cgi/gentoo-x86/net-dns/bind/files/named.init-r12?rev=1.1&content-type=text/plain |
14 |
|
15 |
Index: named.init-r12 |
16 |
=================================================================== |
17 |
#!/sbin/runscript |
18 |
# Copyright 1999-2012 Gentoo Foundation |
19 |
# Distributed under the terms of the GNU General Public License v2 |
20 |
# $Header: /var/cvsroot/gentoo-x86/net-dns/bind/files/named.init-r12,v 1.1 2012/08/24 19:01:09 idl0r Exp $ |
21 |
|
22 |
extra_commands="checkconfig checkzones" |
23 |
extra_started_commands="reload" |
24 |
|
25 |
depend() { |
26 |
need net |
27 |
use logger |
28 |
provide dns |
29 |
} |
30 |
|
31 |
NAMED_CONF=${CHROOT}/etc/bind/named.conf |
32 |
|
33 |
OPENSSL_LIBGOST=${OPENSSL_LIBGOST:-0} |
34 |
MOUNT_CHECK_TIMEOUT=${MOUNT_CHECK_TIMEOUT:-60} |
35 |
|
36 |
_mount() { |
37 |
local from |
38 |
local to |
39 |
local opts |
40 |
local ret=0 |
41 |
|
42 |
if [ "${#}" -lt 3 ]; then |
43 |
eerror "_mount(): to few arguments" |
44 |
return 1 |
45 |
fi |
46 |
|
47 |
from=$1 |
48 |
to=$2 |
49 |
shift 2 |
50 |
|
51 |
opts="${*}" |
52 |
shift $# |
53 |
|
54 |
if [ -z "$(awk "\$2 == \"${to}\" { print \$2 }" /proc/mounts)" ]; then |
55 |
einfo "mounting ${from} to ${to}" |
56 |
mount ${from} ${to} ${opts} |
57 |
ret=$? |
58 |
|
59 |
eend $ret |
60 |
return $ret |
61 |
fi |
62 |
|
63 |
return 0 |
64 |
} |
65 |
|
66 |
_umount() { |
67 |
local dir=$1 |
68 |
local ret=0 |
69 |
|
70 |
if [ -n "$(awk "\$2 == \"${dir}\" { print \$2 }" /proc/mounts)" ]; then |
71 |
ebegin "umounting ${dir}" |
72 |
umount ${dir} |
73 |
ret=$? |
74 |
|
75 |
eend $ret |
76 |
return $ret |
77 |
fi |
78 |
|
79 |
return 0 |
80 |
} |
81 |
|
82 |
_get_pidfile() { |
83 |
# as suggested in bug #107724, bug 335398#c17 |
84 |
[ -n "${PIDFILE}" ] || PIDFILE=${CHROOT}$(\ |
85 |
/usr/sbin/named-checkconf -p ${CHROOT:+-t} ${CHROOT} ${NAMED_CONF#${CHROOT}} | grep 'pid-file' | cut -d\" -f2) |
86 |
[ -z "${PIDFILE}" ] && PIDFILE=${CHROOT}/var/run/named/named.pid |
87 |
} |
88 |
|
89 |
check_chroot() { |
90 |
if [ -n "${CHROOT}" ]; then |
91 |
[ ! -d "${CHROOT}" ] && return 1 |
92 |
[ ! -d "${CHROOT}/dev" ] || [ ! -d "${CHROOT}/etc" ] || [ ! -d "${CHROOT}/var" ] && return 1 |
93 |
[ ! -d "${CHROOT}/var/run" ] || [ ! -d "${CHROOT}/var/log" ] && return 1 |
94 |
[ ! -d "${CHROOT}/etc/bind" ] || [ ! -d "${CHROOT}/var/bind" ] && return 1 |
95 |
[ ! -d "${CHROOT}/var/log/named" ] && return 1 |
96 |
[ ! -c "${CHROOT}/dev/null" ] || [ ! -c "${CHROOT}/dev/zero" ] && return 1 |
97 |
[ ! -c "${CHROOT}/dev/random" ] && [ ! -c "${CHROOT}/dev/urandom" ] && return 1 |
98 |
[ "${CHROOT_GEOIP:-0}" -eq 1 ] && [ ! -d "${CHROOT}/usr/share/GeoIP" ] && return 1 |
99 |
if [ ${OPENSSL_LIBGOST:-0} -eq 1 ]; then |
100 |
if [ -d "/usr/lib64" ]; then |
101 |
[ ! -d "${CHROOT}/usr/lib64/engines" ] && return 1 |
102 |
elif [ -d "/usr/lib" ]; then |
103 |
[ ! -d "${CHROOT}/usr/lib/engines" ] && return 1 |
104 |
fi |
105 |
fi |
106 |
fi |
107 |
|
108 |
return 0 |
109 |
} |
110 |
|
111 |
checkconfig() { |
112 |
ebegin "Checking named configuration" |
113 |
|
114 |
if [ ! -f "${NAMED_CONF}" ] ; then |
115 |
eerror "No ${NAMED_CONF} file exists!" |
116 |
return 1 |
117 |
fi |
118 |
|
119 |
/usr/sbin/named-checkconf ${CHROOT:+-t} ${CHROOT} ${NAMED_CONF#${CHROOT}} || { |
120 |
eerror "named-checkconf failed! Please fix your config first." |
121 |
return 1 |
122 |
} |
123 |
|
124 |
eend 0 |
125 |
return 0 |
126 |
} |
127 |
|
128 |
checkzones() { |
129 |
ebegin "Checking named configuration and zones" |
130 |
/usr/sbin/named-checkconf -z -j ${CHROOT:+-t} ${CHROOT} ${NAMED_CONF#${CHROOT}} |
131 |
eend $? |
132 |
} |
133 |
|
134 |
start() { |
135 |
local piddir |
136 |
|
137 |
ebegin "Starting ${CHROOT:+chrooted }named" |
138 |
|
139 |
if [ -n "${CHROOT}" ]; then |
140 |
if [ ${CHROOT_NOCHECK:-0} -eq 0 ]; then |
141 |
check_chroot || { |
142 |
eend 1 |
143 |
eerror "Your chroot dir ${CHROOT} is inconsistent, please run 'emerge --config net-dns/bind' first" |
144 |
return 1 |
145 |
} |
146 |
fi |
147 |
|
148 |
if [ ${OPENSSL_LIBGOST:-0} -eq 1 ]; then |
149 |
if [ ! -e /usr/lib/engines/libgost.so ]; then |
150 |
eend 1 |
151 |
eerror "Couldn't find /usr/lib/engines/libgost.so but bind has been built with openssl and libgost support" |
152 |
return 1 |
153 |
fi |
154 |
cp -Lp /usr/lib/engines/libgost.so "${CHROOT}/usr/lib/engines/libgost.so" || { |
155 |
eend 1 |
156 |
eerror "Couldn't copy /usr/lib/engines/libgost.so into '${CHROOT}/usr/lib/engines/'" |
157 |
return 1 |
158 |
} |
159 |
fi |
160 |
cp -Lp /etc/localtime "${CHROOT}/etc/localtime" |
161 |
|
162 |
if [ "${CHROOT_NOMOUNT:-0}" -eq 0 ]; then |
163 |
einfo "Mounting chroot dirs" |
164 |
_mount /etc/bind ${CHROOT}/etc/bind -o bind |
165 |
_mount /var/bind ${CHROOT}/var/bind -o bind |
166 |
_mount /var/log/named ${CHROOT}/var/log/named -o bind |
167 |
if [ "${CHROOT_GEOIP:-0}" -eq 1 ]; then |
168 |
_mount /usr/share/GeoIP ${CHROOT}/usr/share/GeoIP -o bind |
169 |
fi |
170 |
fi |
171 |
fi |
172 |
|
173 |
checkconfig || { eend 1; return 1; } |
174 |
|
175 |
# create piddir (usually /var/run/named) if necessary, bug 334535 |
176 |
_get_pidfile |
177 |
piddir="${PIDFILE%/*}" |
178 |
checkpath -q -d -o root:named -m 0770 "${piddir}" || { |
179 |
eend 1 |
180 |
return 1 |
181 |
} |
182 |
|
183 |
# In case someone have $CPU set in /etc/conf.d/named |
184 |
if [ -n "${CPU}" ] && [ "${CPU}" -gt 0 ]; then |
185 |
CPU="-n ${CPU}" |
186 |
fi |
187 |
|
188 |
start-stop-daemon --start --pidfile ${PIDFILE} \ |
189 |
--nicelevel ${NAMED_NICELEVEL:-0} \ |
190 |
--exec /usr/sbin/named \ |
191 |
-- -u named ${CPU} ${OPTIONS} ${CHROOT:+-t} ${CHROOT} |
192 |
eend $? |
193 |
} |
194 |
|
195 |
stop() { |
196 |
local reported=0 |
197 |
|
198 |
ebegin "Stopping ${CHROOT:+chrooted }named" |
199 |
|
200 |
# Workaround for now, until openrc's restart has been fixed. |
201 |
# openrc doesn't care about a restart() function in init scripts. |
202 |
if [ "${RC_CMD}" = "restart" ]; then |
203 |
if [ -n "${CHROOT}" -a ${CHROOT_NOCHECK:-0} -eq 0 ]; then |
204 |
check_chroot || { |
205 |
eend 1 |
206 |
eerror "Your chroot dir ${CHROOT} is inconsistent, please run 'emerge --config net-dns/bind' first" |
207 |
return 1 |
208 |
} |
209 |
fi |
210 |
|
211 |
checkconfig || { eend 1; return 1; } |
212 |
fi |
213 |
|
214 |
# -R 10, bug 335398 |
215 |
_get_pidfile |
216 |
start-stop-daemon --stop --retry 10 --pidfile $PIDFILE \ |
217 |
--exec /usr/sbin/named |
218 |
|
219 |
if [ -n "${CHROOT}" ] && [ "${CHROOT_NOMOUNT:-0}" -eq 0 ]; then |
220 |
ebegin "Umounting chroot dirs" |
221 |
|
222 |
# just to be sure everything gets clean |
223 |
while fuser -s ${CHROOT} 2>/dev/null; do |
224 |
if [ "${reported}" -eq 0 ]; then |
225 |
einfo "Waiting until all named processes are stopped (max. ${MOUNT_CHECK_TIMEOUT} seconds)" |
226 |
elif [ "${reported}" -eq "${MOUNT_CHECK_TIMEOUT}" ]; then |
227 |
eerror "Waiting until all named processes are stopped failed!" |
228 |
eend 1 |
229 |
break |
230 |
fi |
231 |
sleep 1 |
232 |
reported=$((reported+1)) |
233 |
done |
234 |
|
235 |
[ "${CHROOT_GEOIP:-0}" -eq 1 ] && _umount ${CHROOT}/usr/share/GeoIP |
236 |
_umount ${CHROOT}/etc/bind |
237 |
_umount ${CHROOT}/var/log/named |
238 |
_umount ${CHROOT}/var/bind |
239 |
fi |
240 |
|
241 |
eend $? |
242 |
} |
243 |
|
244 |
reload() { |
245 |
local ret |
246 |
|
247 |
ebegin "Reloading named.conf and zone files" |
248 |
|
249 |
checkconfig || { eend 1; return 1; } |
250 |
|
251 |
_get_pidfile |
252 |
if [ -n "${PIDFILE}" ]; then |
253 |
start-stop-daemon --pidfile $PIDFILE --signal HUP |
254 |
ret=$? |
255 |
else |
256 |
ewarn "Unable to determine the pidfile... this is" |
257 |
ewarn "a fallback mode. Please check your installation!" |
258 |
|
259 |
$RC_SERVICE restart |
260 |
ret=$? |
261 |
fi |
262 |
|
263 |
eend $ret |
264 |
} |