Skip to content

Instantly share code, notes, and snippets.

/gist:5cf45bc74fc1f7f0f579 Secret
Created May 20, 2015

Embed
What would you like to do?
#!/bin/bash
NAMED_ARGS=
[ -f /etc/conf.d/named ] && . /etc/conf.d/named
. /etc/rc.conf
. /etc/rc.d/functions
PID=`pidof -o %PPID /usr/sbin/named`
case "$1" in
start)
stat_busy "Starting BIND (chroot)"
# create chroot directories
mkdir -p ${CHROOT}/{dev,etc} ${CHROOT}/var/named/slave ${CHROOT}/var/{run,log} ${CHROOT}/usr/lib/engines
# copy necessary files
cp /etc/named.conf ${CHROOT}/etc/
cp /etc/localtime ${CHROOT}/etc/
cp -a /var/named/* ${CHROOT}/var/named/
cp /usr/lib/engines/libgost.so ${CHROOT}/usr/lib/engines/
# create block devices
mknod ${CHROOT}/dev/null c 1 3
mknod ${CHROOT}/dev/random c 1 8
# set permissions
chown root:named ${CHROOT}
chmod 750 ${CHROOT}
chown -R named:named ${CHROOT}/var/named/slave
chown named:named ${CHROOT}/var/{run,log}
chmod 666 ${CHROOT}/dev/{null,random}
[ -z "$PID" ] && /usr/sbin/named ${NAMED_ARGS} -t ${CHROOT}
if [ $? -gt 0 ]; then
stat_fail
else
add_daemon named-chroot
stat_done
fi
;;
stop)
stat_busy "Stopping BIND (chroot)"
[ ! -z "$PID" ] && kill $PID &> /dev/null
if [ $? -gt 0 ]; then
stat_fail
else
rm_daemon named-chroot
rm -rf ${CHROOT}
stat_done
fi
;;
restart)
$0 stop
sleep 1
$0 start
;;
reload)
stat_busy "Reloading BIND"
[ ! -z "$PID" ] && rndc reload &>/dev/null || kill -HUP $PID &>/dev/null
if [ $? -gt 0 ]; then
stat_fail
else
stat_done
fi
;;
*)
echo "usage: $0 {start|stop|reload|restart}"
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.