2009-08-26 17:00:38 +02:00
|
|
|
#!/bin/sh
|
|
|
|
# Start/stop/restart the BIND name server daemon (named).
|
|
|
|
|
2021-09-16 04:52:54 +02:00
|
|
|
# Start BIND. By default this will run with user "named". If you'd like to
|
|
|
|
# change this or other options, see: /etc/default/named
|
2009-08-26 17:00:38 +02:00
|
|
|
|
|
|
|
# You might also consider running BIND in a "chroot jail",
|
|
|
|
# a discussion of which may be found in
|
|
|
|
# /usr/doc/Linux-HOWTOs/Chroot-BIND-HOWTO.
|
|
|
|
|
2020-02-18 06:20:50 +01:00
|
|
|
# One last note: rndc has a lot of other nice features that it is not
|
2011-04-25 15:37:00 +02:00
|
|
|
# within the scope of this start/stop/restart script to support.
|
|
|
|
# For more details, see "man rndc" or just type "rndc" to see the options.
|
2009-08-26 17:00:38 +02:00
|
|
|
|
2011-04-25 15:37:00 +02:00
|
|
|
# Load command defaults:
|
|
|
|
if [ -f /etc/default/named ] ; then . /etc/default/named ; fi
|
|
|
|
if [ -f /etc/default/rndc ] ; then . /etc/default/rndc ; fi
|
2009-08-26 17:00:38 +02:00
|
|
|
|
2021-09-25 03:05:55 +02:00
|
|
|
# In case /etc/default/named was missing, provide fallbacks:
|
|
|
|
if [ -z "$NAMED_USER" ]; then
|
|
|
|
NAMED_USER="named"
|
2021-09-16 04:52:54 +02:00
|
|
|
fi
|
2021-09-25 03:05:55 +02:00
|
|
|
if [ -z "$NAMED_GROUP" ]; then
|
|
|
|
NAMED_GROUP="named"
|
2021-09-16 04:52:54 +02:00
|
|
|
fi
|
2021-09-25 03:05:55 +02:00
|
|
|
if [ -z "$NAMED_OPTIONS" ]; then
|
|
|
|
NAMED_OPTIONS="-u $NAMED_USER"
|
2021-09-16 04:52:54 +02:00
|
|
|
fi
|
|
|
|
|
2020-02-18 06:20:50 +01:00
|
|
|
# Sanity check. If /usr/sbin/named is missing then it
|
2011-04-25 15:37:00 +02:00
|
|
|
# doesn't make much sense to try to run this script:
|
2009-08-26 17:00:38 +02:00
|
|
|
if [ ! -x /usr/sbin/named ]; then
|
|
|
|
echo "/etc/rc.d/rc.bind: no /usr/sbin/named found (or not executable); cannot start."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2020-02-18 06:20:50 +01:00
|
|
|
# Start BIND. As many times as you like. ;-)
|
2009-08-26 17:00:38 +02:00
|
|
|
# Seriously, don't run "rc.bind start" if BIND is already
|
|
|
|
# running or you'll get more than one copy running.
|
|
|
|
bind_start() {
|
2020-03-02 20:05:10 +01:00
|
|
|
# Make sure /var/run/named exists:
|
|
|
|
mkdir -p /var/run/named
|
2021-09-16 04:52:54 +02:00
|
|
|
# Make sure that /var/run/named has correct ownership:
|
2021-09-25 03:05:55 +02:00
|
|
|
chown -R ${NAMED_USER}:${NAMED_GROUP} /var/run/named
|
2023-11-07 20:57:12 +01:00
|
|
|
if [ "$NAMED_CHOWN" = "YES" ]; then
|
|
|
|
# Make sure that /var/named has correct ownership:
|
|
|
|
chown -R ${NAMED_USER}:${NAMED_GROUP} /var/named
|
|
|
|
if [ -r /etc/rndc.key ]; then
|
|
|
|
# Make sure that /etc/rndc.key has correct ownership:
|
|
|
|
chown ${NAMED_USER}:${NAMED_GROUP} /etc/rndc.key
|
|
|
|
fi
|
2021-09-19 02:13:58 +02:00
|
|
|
fi
|
2020-03-02 20:05:10 +01:00
|
|
|
# Start named:
|
2009-08-26 17:00:38 +02:00
|
|
|
if [ -x /usr/sbin/named ]; then
|
2011-04-25 15:37:00 +02:00
|
|
|
echo "Starting BIND: /usr/sbin/named $NAMED_OPTIONS"
|
|
|
|
/usr/sbin/named $NAMED_OPTIONS
|
2009-08-26 17:00:38 +02:00
|
|
|
sleep 1
|
|
|
|
fi
|
2020-03-02 20:05:10 +01:00
|
|
|
# Make sure that named started:
|
2009-08-26 17:00:38 +02:00
|
|
|
if ! ps axc | grep -q named ; then
|
|
|
|
echo "WARNING: named did not start."
|
2011-04-25 15:37:00 +02:00
|
|
|
echo "Attempting to start named again: /usr/sbin/named $NAMED_OPTIONS"
|
|
|
|
/usr/sbin/named $NAMED_OPTIONS
|
2009-08-26 17:00:38 +02:00
|
|
|
sleep 1
|
|
|
|
if ps axc | grep -q named ; then
|
|
|
|
echo "SUCCESS: named started."
|
|
|
|
else
|
2020-02-18 06:20:50 +01:00
|
|
|
echo "FAILED: Sorry, a second attempt to start named has also failed."
|
|
|
|
echo "There may be a configuration error that needs fixing. Good luck!"
|
2009-08-26 17:00:38 +02:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# Stop all running copies of BIND (/usr/sbin/named):
|
|
|
|
bind_stop() {
|
2021-09-03 20:51:49 +02:00
|
|
|
# If you've set up rndc, we can use this to make shutting down BIND faster.
|
|
|
|
# If you have /etc/rndc.conf, or you have /etc/rndc.key, or $RNDC_OPTIONS is
|
|
|
|
# not empty, we'll try it.
|
|
|
|
if [ -r /etc/rndc.conf -o -r /etc/rndc.key -o ! -z "$RNDC_OPTIONS" ]; then
|
|
|
|
if [ -z "$RNDC_OPTIONS" ]; then
|
|
|
|
echo "Stopping BIND: /usr/sbin/rndc stop"
|
|
|
|
else
|
|
|
|
echo "Stopping BIND: /usr/sbin/rndc $RNDC_OPTIONS stop"
|
|
|
|
fi
|
|
|
|
/usr/sbin/rndc $RNDC_OPTIONS stop
|
|
|
|
# Wait for up to $TIMEOUT seconds before moving on to try killall:
|
|
|
|
TIMEOUT=${TIMEOUT:-10}
|
|
|
|
while [ "$TIMEOUT" -gt "0" ]; do
|
|
|
|
# Exit the timeout loop if there are no named processes:
|
|
|
|
if ! ps axco command | grep -q -e "^named$"; then
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
sleep 1
|
|
|
|
TIMEOUT=$(expr $TIMEOUT - 1)
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
# Kill named processes if there are any running:
|
|
|
|
if ps axco command | grep -q -e "^named$"; then
|
|
|
|
echo "Stopping all named processes in this namespace: /bin/killall -SIGTERM --ns \$\$ named"
|
|
|
|
/bin/killall -SIGTERM --ns $$ named 2> /dev/null
|
2009-08-26 17:00:38 +02:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# Reload BIND:
|
|
|
|
bind_reload() {
|
2021-09-03 20:51:49 +02:00
|
|
|
/usr/sbin/rndc $RNDC_OPTIONS reload
|
2009-08-26 17:00:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Restart BIND:
|
|
|
|
bind_restart() {
|
|
|
|
bind_stop
|
|
|
|
bind_start
|
|
|
|
}
|
|
|
|
|
|
|
|
# Get BIND status:
|
|
|
|
bind_status() {
|
2021-09-03 20:51:49 +02:00
|
|
|
/usr/sbin/rndc $RNDC_OPTIONS status
|
2009-08-26 17:00:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
case "$1" in
|
|
|
|
'start')
|
|
|
|
bind_start
|
|
|
|
;;
|
|
|
|
'stop')
|
|
|
|
bind_stop
|
|
|
|
;;
|
|
|
|
'reload')
|
|
|
|
bind_reload
|
|
|
|
;;
|
|
|
|
'restart')
|
|
|
|
bind_restart
|
|
|
|
;;
|
|
|
|
'status')
|
|
|
|
bind_status
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "usage $0 start|stop|reload|restart|status"
|
|
|
|
esac
|