Skip to content

Commit

Permalink
knot: test knot w/default .conf
Browse files Browse the repository at this point in the history
knot may need network binds and be unable to run with production config
  • Loading branch information
msimerson committed Sep 22, 2024
1 parent 88450b1 commit 5ba5b48
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions provision/knot.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/bin/sh

. mail-toaster.sh || exit
set -e

. mail-toaster.sh

export JAIL_START_EXTRA=""
export JAIL_CONF_EXTRA=""
Expand All @@ -11,10 +13,9 @@ mt6-include user
install_knot()
{
tell_status "installing Knot DNS 3"
stage_pkg_install knot3 rsync || exit
stage_pkg_install knot3 rsync

install_nrpe
install_sentry
}

install_nrpe()
Expand All @@ -34,35 +35,35 @@ configure_knot()
{
for _d in etc home home/knot; do
if [ ! -d "$STAGE_MNT/data/$_d" ]; then
mkdir "$STAGE_MNT/data/$_d" || exit
mkdir "$STAGE_MNT/data/$_d"
fi
done

chown -R 553:553 "$STAGE_MNT/data/home/knot"

local _cfg="$STAGE_MNT/data/etc/knot.conf"
if [ -f $_cfg ]; then
tell_status "preserving knot.conf"
else
tell_status "installing default knot.conf"
cp "$STAGE_MNT/usr/local/etc/knot/knot.conf.sample" "$_cfg" || exit 1
local _cfg="$STAGE_MNT/usr/local/etc/knot/knot.conf"
if [ ! -f "$_cfg" ] && [ -f "$_cfg.sample" ]; then
tell_status "installing default $_cfg"
cp "$_cfg.sample" "$_cfg"
fi

if grep -qs '^#[[:space:]]*listen' "$_cfg"; then
sed -i '' \
-e '/^#[[:space:]]*listen:/ s/^#//' \
"$_cfg"
fi

stage_sysrc sshd_enable=YES
stage_sysrc knot_enable=YES
stage_sysrc knot_config=/data/etc/knot.conf
stage_exec pw user mod knot -d /data/home/knot -s /bin/sh

preserve_passdb knot
stage_exec pw user mod knot -d /data/home/knot -s /bin/sh
}

start_knot()
{
tell_status "starting knot daemon"
stage_exec service knot start || exit 1
stage_exec service knot start
}

test_knot()
Expand All @@ -74,13 +75,18 @@ test_knot()
echo "it worked."

tell_status "testing UDP DNS query"
drill -Q www.example.com @"$(get_jail_ip stage)" || exit 1
drill -Q www.example.com @"$(get_jail_ip stage)"

tell_status "testing TCP DNS query"
drill -Q -t www.example.com @"$(get_jail_ip stage)" || exit 1
drill -Q -t www.example.com @"$(get_jail_ip stage)"

if [ -f "$STAGE_MNT/data/etc/knot.conf" ]; then
tell_status "switching knot config to /data/etc/knot.conf"
stage_sysrc knot_config=/data/etc/knot.conf
fi
}

base_snapshot_exists || exit
base_snapshot_exists
create_staged_fs knot
start_staged_jail knot
install_knot
Expand Down

0 comments on commit 5ba5b48

Please sign in to comment.