Lines 16-71
NAMED_CONF=${CHROOT}/etc/bind/named.conf
Link Here
|
16 |
OPENSSL_LIBGOST=${OPENSSL_LIBGOST:-0} |
16 |
OPENSSL_LIBGOST=${OPENSSL_LIBGOST:-0} |
17 |
MOUNT_CHECK_TIMEOUT=${MOUNT_CHECK_TIMEOUT:-60} |
17 |
MOUNT_CHECK_TIMEOUT=${MOUNT_CHECK_TIMEOUT:-60} |
18 |
|
18 |
|
19 |
_mount() { |
19 |
_bindmount() { |
20 |
local from |
20 |
if ! mountpoint -q -- "$2"; then |
21 |
local to |
21 |
ebegin "mounting $1 to $2" |
22 |
local opts |
22 |
mount -o bind -- "$1" "$2" |
23 |
local ret=0 |
23 |
eend $? |
24 |
|
|
|
25 |
if [ "${#}" -lt 3 ]; then |
26 |
eerror "_mount(): to few arguments" |
27 |
return 1 |
28 |
fi |
29 |
|
30 |
from=$1 |
31 |
to=$2 |
32 |
shift 2 |
33 |
|
34 |
opts="${*}" |
35 |
shift $# |
36 |
|
37 |
if [ -z "$(awk "\$2 == \"${to}\" { print \$2 }" /proc/mounts)" ]; then |
38 |
einfo "mounting ${from} to ${to}" |
39 |
mount ${from} ${to} ${opts} |
40 |
ret=$? |
41 |
|
42 |
eend $ret |
43 |
return $ret |
44 |
fi |
24 |
fi |
45 |
|
|
|
46 |
return 0 |
47 |
} |
25 |
} |
48 |
|
26 |
|
49 |
_umount() { |
27 |
_umount() { |
50 |
local dir=$1 |
28 |
if mountpoint -q -- "$1"; then |
51 |
local ret=0 |
29 |
ebegin "umounting $1" |
52 |
|
30 |
umount -- "$1" |
53 |
if [ -n "$(awk "\$2 == \"${dir}\" { print \$2 }" /proc/mounts)" ]; then |
31 |
eend $? |
54 |
ebegin "umounting ${dir}" |
|
|
55 |
umount ${dir} |
56 |
ret=$? |
57 |
|
58 |
eend $ret |
59 |
return $ret |
60 |
fi |
32 |
fi |
61 |
|
|
|
62 |
return 0 |
63 |
} |
33 |
} |
64 |
|
34 |
|
65 |
_get_pidfile() { |
35 |
_get_pidfile() { |
66 |
# as suggested in bug #107724, bug 335398#c17 |
36 |
# as suggested in bug #107724, bug 335398#c17 |
67 |
[ -n "${PIDFILE}" ] || PIDFILE=${CHROOT}$(\ |
37 |
[ -n "${PIDFILE}" ] || PIDFILE=${CHROOT}$(\ |
68 |
/usr/sbin/named-checkconf -p ${CHROOT:+-t} ${CHROOT} ${NAMED_CONF#${CHROOT}} | grep 'pid-file' | cut -d\" -f2) |
38 |
/usr/sbin/named-checkconf -p ${CHROOT:+-t} ${CHROOT} "${NAMED_CONF#${CHROOT}}" | grep 'pid-file' | cut -d\" -f2) |
69 |
[ -z "${PIDFILE}" ] && PIDFILE=${CHROOT}/run/named/named.pid |
39 |
[ -z "${PIDFILE}" ] && PIDFILE=${CHROOT}/run/named/named.pid |
70 |
} |
40 |
} |
71 |
|
41 |
|
Lines 79-85
check_chroot() {
Link Here
|
79 |
[ ! -c "${CHROOT}/dev/null" ] || [ ! -c "${CHROOT}/dev/zero" ] && return 1 |
49 |
[ ! -c "${CHROOT}/dev/null" ] || [ ! -c "${CHROOT}/dev/zero" ] && return 1 |
80 |
[ ! -c "${CHROOT}/dev/urandom" ] && return 1 |
50 |
[ ! -c "${CHROOT}/dev/urandom" ] && return 1 |
81 |
[ "${CHROOT_GEOIP:-0}" -eq 1 ] && [ ! -d "${CHROOT}/usr/share/GeoIP" ] && return 1 |
51 |
[ "${CHROOT_GEOIP:-0}" -eq 1 ] && [ ! -d "${CHROOT}/usr/share/GeoIP" ] && return 1 |
82 |
if [ ${OPENSSL_LIBGOST:-0} -eq 1 ]; then |
52 |
if [ "${OPENSSL_LIBGOST:-0}" -eq 1 ]; then |
83 |
if [ -d "/usr/lib64" ]; then |
53 |
if [ -d "/usr/lib64" ]; then |
84 |
[ ! -d "${CHROOT}/usr/lib64/engines" ] && return 1 |
54 |
[ ! -d "${CHROOT}/usr/lib64/engines" ] && return 1 |
85 |
elif [ -d "/usr/lib" ]; then |
55 |
elif [ -d "/usr/lib" ]; then |
Lines 99-105
checkconfig() {
Link Here
|
99 |
return 1 |
69 |
return 1 |
100 |
fi |
70 |
fi |
101 |
|
71 |
|
102 |
/usr/sbin/named-checkconf ${CHROOT:+-t} ${CHROOT} ${NAMED_CONF#${CHROOT}} || { |
72 |
/usr/sbin/named-checkconf ${CHROOT:+-t} ${CHROOT} "${NAMED_CONF#${CHROOT}}" || { |
103 |
eerror "named-checkconf failed! Please fix your config first." |
73 |
eerror "named-checkconf failed! Please fix your config first." |
104 |
return 1 |
74 |
return 1 |
105 |
} |
75 |
} |
Lines 110-116
checkconfig() {
Link Here
|
110 |
|
80 |
|
111 |
checkzones() { |
81 |
checkzones() { |
112 |
ebegin "Checking named configuration and zones" |
82 |
ebegin "Checking named configuration and zones" |
113 |
/usr/sbin/named-checkconf -z -j ${CHROOT:+-t} ${CHROOT} ${NAMED_CONF#${CHROOT}} |
83 |
/usr/sbin/named-checkconf -z -j ${CHROOT:+-t} ${CHROOT} "${NAMED_CONF#${CHROOT}}" |
114 |
eend $? |
84 |
eend $? |
115 |
} |
85 |
} |
116 |
|
86 |
|
Lines 120-126
start() {
Link Here
|
120 |
ebegin "Starting ${CHROOT:+chrooted }named" |
90 |
ebegin "Starting ${CHROOT:+chrooted }named" |
121 |
|
91 |
|
122 |
if [ -n "${CHROOT}" ]; then |
92 |
if [ -n "${CHROOT}" ]; then |
123 |
if [ ${CHROOT_NOCHECK:-0} -eq 0 ]; then |
93 |
if [ "${CHROOT_NOCHECK:-0}" -eq 0 ]; then |
124 |
check_chroot || { |
94 |
check_chroot || { |
125 |
eend 1 |
95 |
eend 1 |
126 |
eerror "Your chroot dir ${CHROOT} is inconsistent, please run 'emerge --config net-dns/bind' first" |
96 |
eerror "Your chroot dir ${CHROOT} is inconsistent, please run 'emerge --config net-dns/bind' first" |
Lines 128-134
start() {
Link Here
|
128 |
} |
98 |
} |
129 |
fi |
99 |
fi |
130 |
|
100 |
|
131 |
if [ ${OPENSSL_LIBGOST:-0} -eq 1 ]; then |
101 |
if [ "${OPENSSL_LIBGOST:-0}" -eq 1 ]; then |
132 |
if [ ! -e /usr/lib/engines/libgost.so ]; then |
102 |
if [ ! -e /usr/lib/engines/libgost.so ]; then |
133 |
eend 1 |
103 |
eend 1 |
134 |
eerror "Couldn't find /usr/lib/engines/libgost.so but bind has been built with openssl and libgost support" |
104 |
eerror "Couldn't find /usr/lib/engines/libgost.so but bind has been built with openssl and libgost support" |
Lines 144-154
start() {
Link Here
|
144 |
|
114 |
|
145 |
if [ "${CHROOT_NOMOUNT:-0}" -eq 0 ]; then |
115 |
if [ "${CHROOT_NOMOUNT:-0}" -eq 0 ]; then |
146 |
einfo "Mounting chroot dirs" |
116 |
einfo "Mounting chroot dirs" |
147 |
_mount /etc/bind ${CHROOT}/etc/bind -o bind |
117 |
_bindmount /etc/bind "${CHROOT}/etc/bind" |
148 |
_mount /var/bind ${CHROOT}/var/bind -o bind |
118 |
_bindmount /var/bind "${CHROOT}/var/bind" |
149 |
_mount /var/log/named ${CHROOT}/var/log/named -o bind |
119 |
_bindmount /var/log/named "${CHROOT}/var/log/named" |
150 |
if [ "${CHROOT_GEOIP:-0}" -eq 1 ]; then |
120 |
if [ "${CHROOT_GEOIP:-0}" -eq 1 ]; then |
151 |
_mount /usr/share/GeoIP ${CHROOT}/usr/share/GeoIP -o bind |
121 |
_bindmount /usr/share/GeoIP "${CHROOT}/usr/share/GeoIP" |
152 |
fi |
122 |
fi |
153 |
fi |
123 |
fi |
154 |
|
124 |
|
Lines 173-194
start() {
Link Here
|
173 |
CPU="-n ${CPU}" |
143 |
CPU="-n ${CPU}" |
174 |
fi |
144 |
fi |
175 |
|
145 |
|
176 |
start-stop-daemon --start --pidfile ${PIDFILE} \ |
146 |
start-stop-daemon --start --pidfile "${PIDFILE}" \ |
177 |
--nicelevel ${NAMED_NICELEVEL:-0} \ |
147 |
--nicelevel "${NAMED_NICELEVEL:-0}" \ |
178 |
--exec /usr/sbin/named \ |
148 |
--exec /usr/sbin/named \ |
179 |
-- -u named ${CPU} ${OPTIONS} ${CHROOT:+-t} ${CHROOT} |
149 |
-- -u named ${CPU} ${OPTIONS} ${CHROOT:+-t} ${CHROOT} |
180 |
eend $? |
150 |
eend $? |
181 |
} |
151 |
} |
182 |
|
152 |
|
183 |
stop() { |
153 |
stop() { |
184 |
local reported=0 |
154 |
local reported |
|
|
155 |
reported=0 |
185 |
|
156 |
|
186 |
ebegin "Stopping ${CHROOT:+chrooted }named" |
157 |
ebegin "Stopping ${CHROOT:+chrooted }named" |
187 |
|
158 |
|
188 |
# Workaround for now, until openrc's restart has been fixed. |
159 |
# Workaround for now, until openrc's restart has been fixed. |
189 |
# openrc doesn't care about a restart() function in init scripts. |
160 |
# openrc doesn't care about a restart() function in init scripts. |
190 |
if [ "${RC_CMD}" = "restart" ]; then |
161 |
if [ "${RC_CMD}" = "restart" ]; then |
191 |
if [ -n "${CHROOT}" -a ${CHROOT_NOCHECK:-0} -eq 0 ]; then |
162 |
if [ -n "${CHROOT}" ] && [ "${CHROOT_NOCHECK:-0}" -eq 0 ]; then |
192 |
check_chroot || { |
163 |
check_chroot || { |
193 |
eend 1 |
164 |
eend 1 |
194 |
eerror "Your chroot dir ${CHROOT} is inconsistent, please run 'emerge --config net-dns/bind' first" |
165 |
eerror "Your chroot dir ${CHROOT} is inconsistent, please run 'emerge --config net-dns/bind' first" |
Lines 201-214
stop() {
Link Here
|
201 |
|
172 |
|
202 |
# -R 10, bug 335398 |
173 |
# -R 10, bug 335398 |
203 |
_get_pidfile |
174 |
_get_pidfile |
204 |
start-stop-daemon --stop --retry 10 --pidfile $PIDFILE \ |
175 |
start-stop-daemon --stop --retry 10 --pidfile "${PIDFILE}" \ |
205 |
--exec /usr/sbin/named |
176 |
--exec /usr/sbin/named |
206 |
|
177 |
|
207 |
if [ -n "${CHROOT}" ] && [ "${CHROOT_NOMOUNT:-0}" -eq 0 ]; then |
178 |
if [ -n "${CHROOT}" ] && [ "${CHROOT_NOMOUNT:-0}" -eq 0 ]; then |
208 |
ebegin "Umounting chroot dirs" |
179 |
ebegin "Umounting chroot dirs" |
209 |
|
180 |
|
210 |
# just to be sure everything gets clean |
181 |
# just to be sure everything gets clean |
211 |
while fuser -s ${CHROOT} 2>/dev/null; do |
182 |
while fuser -s "${CHROOT}" 2>/dev/null; do |
212 |
if [ "${reported}" -eq 0 ]; then |
183 |
if [ "${reported}" -eq 0 ]; then |
213 |
einfo "Waiting until all named processes are stopped (max. ${MOUNT_CHECK_TIMEOUT} seconds)" |
184 |
einfo "Waiting until all named processes are stopped (max. ${MOUNT_CHECK_TIMEOUT} seconds)" |
214 |
elif [ "${reported}" -eq "${MOUNT_CHECK_TIMEOUT}" ]; then |
185 |
elif [ "${reported}" -eq "${MOUNT_CHECK_TIMEOUT}" ]; then |
Lines 220-229
stop() {
Link Here
|
220 |
reported=$((reported+1)) |
191 |
reported=$((reported+1)) |
221 |
done |
192 |
done |
222 |
|
193 |
|
223 |
[ "${CHROOT_GEOIP:-0}" -eq 1 ] && _umount ${CHROOT}/usr/share/GeoIP |
194 |
[ "${CHROOT_GEOIP:-0}" -eq 1 ] && _umount "${CHROOT}/usr/share/GeoIP" |
224 |
_umount ${CHROOT}/etc/bind |
195 |
_umount "${CHROOT}/etc/bind" |
225 |
_umount ${CHROOT}/var/log/named |
196 |
_umount "${CHROOT}/var/log/named" |
226 |
_umount ${CHROOT}/var/bind |
197 |
_umount "${CHROOT}/var/bind" |
227 |
fi |
198 |
fi |
228 |
|
199 |
|
229 |
eend $? |
200 |
eend $? |
Lines 238-244
reload() {
Link Here
|
238 |
|
209 |
|
239 |
_get_pidfile |
210 |
_get_pidfile |
240 |
if [ -n "${PIDFILE}" ]; then |
211 |
if [ -n "${PIDFILE}" ]; then |
241 |
start-stop-daemon --pidfile $PIDFILE --signal HUP |
212 |
start-stop-daemon --pidfile "${PIDFILE}" --signal HUP |
242 |
ret=$? |
213 |
ret=$? |
243 |
else |
214 |
else |
244 |
ewarn "Unable to determine the pidfile... this is" |
215 |
ewarn "Unable to determine the pidfile... this is" |