File entrypoint.sh of Package opensuse-nsd-image
#!/bin/sh
set -e
DEBUG=${DEBUG:-"0"}
[ "${DEBUG}" = "1" ] && set -x
DATA_DIR=/data
NSD_USER=_nsd
create_bind_data_dir() {
mkdir -p ${DATA_DIR}
# populate default bind configuration if it does not exist
if test ! -d ${DATA_DIR}/etc; then
mkdir -p ${DATA_DIR}/etc/zones
chmod 0750 ${DATA_DIR}/etc
chmod 0750 ${DATA_DIR}/etc/zones
mv /etc/nsd/nsd.conf.sample ${DATA_DIR}/etc/
sed -i -e 's|"/etc/nsd/|"${DATA_DIR}/etc/nsd/|g' ${DATA_DIR}/etc/nsd.conf.sample
chown --recursive _nsd:_nsd ${DATA_DIR}/etc
fi
rm -rf /etc/nsd/zones
ln -sf ${DATA_DIR}/etc/nsd.conf /etc/nsd/nsd.conf
ln -sf ${DATA_DIR}/etc/nsd/zones /etc/nsd/zones
chown -R ${NSD_USER}:${NSD_USER} ${DATA_DIR}/etc
if test ! -d ${DATA_DIR}/lib; then
mv /var/lib/nsd ${DATA_DIR}/lib
chown -R ${NSD_USER}:${NSD_USER} ${DATA_DIR}/lib
fi
rm -rf /var/lib/nsd
ln -sf ${DATA_DIR}/lib /var/lib/nsd
}
create_pid_dir() {
mkdir -m 0775 -p /var/run/nsd
chown ${NSD_USER}:${NSD_USER} /var/run/nsd
}
create_pid_dir
create_bind_data_dir
# allow arguments to be passed to nsd
if test "${1:0:1}" = '-'; then
EXTRA_ARGS="$@"
set --
elif test "${1}" = "nsd" || test "${1}" = "/usr/sbin/nsd"; then
shift 1
EXTRA_ARGS="${@}"
set --
fi
# default behaviour is to launch nsd
if test -z ${1}; then
echo "Starting nsd..."
exec /usr/sbin/nsd -u ${NSD_USER} -t ${DATA_DIR} -d ${EXTRA_ARGS}
else
exec "$@"
fi