Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions DnsServerApp/DnsServerApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
</ItemGroup>

<ItemGroup>
<None Update="openrc.service">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="start.bat">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down
109 changes: 86 additions & 23 deletions DnsServerApp/install.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
#!/bin/sh

cleanup() {
# On Alpine Linux get rid of virtual packages installed in support for this script.
# If none was installed, just fail silently
if $alpineLinux; then
apk del .deps > /dev/null 2>&1
fi
}

trap cleanup INT TERM EXIT

dotnetDir="/opt/dotnet"
dotnetVersion="8.0"
dotnetRuntime="Microsoft.AspNetCore.App 8.0."
Expand Down Expand Up @@ -27,6 +37,29 @@ echo ""
mkdir -p $dnsDir
echo "" > $installLog

if command -v apk >/dev/null 2>&1
then
# On Alpine Linux we need bash & curl to install dotnet
alpineLinux=true
apk update >> $installLog 2>&1
deps=""
# Check for bash
if ! command -v bash >/dev/null 2>&1; then
deps="$deps bash"
fi
# Check for curl
if ! command -v curl >/dev/null 2>&1; then
deps="$deps curl"
fi
# Install missing packages, if any
if [ -n "$deps" ]; then
echo "Installing packages needed for the installation: $deps"
apk add --no-cache --virtual .deps $deps
fi
else
alpineLinux=false
fi

if dotnet --list-runtimes 2> /dev/null | grep -q "$dotnetRuntime";
then
dotnetFound="yes"
Expand All @@ -49,6 +82,12 @@ else

curl -sSL $dotnetUrl | bash /dev/stdin -c $dotnetVersion --runtime aspnetcore --no-path --install-dir $dotnetDir --verbose >> $installLog 2>&1

# On Alpine Linux dotnet requires libstdc++
if $alpineLinux; then
echo "Installing ASP.NET Core Runtime dependencies..."
apk add --no-cache libstdc++ >> $installLog 2>&1
fi

if [ ! -f "/usr/bin/dotnet" ]
then
ln -s $dotnetDir/dotnet /usr/bin >> $installLog 2>&1
Expand Down Expand Up @@ -166,34 +205,58 @@ fi

echo ""

if ! [ "$(ps --no-headers -o comm 1 | tr -d '\n')" = "systemd" ]
installed=false
if [ "$(ps -o comm 1 | grep -v COMMAND)" = "systemd" ]
then
echo "Failed to install Technitium DNS Server: systemd was not detected."
echo "Please read the 'Installing DNS Server Manually' section in this blog post to understand how to manually install the DNS server on your distro: https://blog.technitium.com/2017/11/running-dns-server-on-ubuntu-linux.html"
exit 1
fi
if [ -f "/etc/systemd/system/dns.service" ]
then
echo "Restarting systemd service..."
systemctl restart dns.service >> $installLog 2>&1
else
echo "Configuring systemd service..."
cp $dnsDir/systemd.service /etc/systemd/system/dns.service
systemctl enable dns.service >> $installLog 2>&1

systemctl stop systemd-resolved >> $installLog 2>&1
systemctl disable systemd-resolved >> $installLog 2>&1

systemctl start dns.service >> $installLog 2>&1

rm /etc/resolv.conf >> $installLog 2>&1
echo -e "# Generated by Technitium DNS Server Installer\n\nnameserver 127.0.0.1" > /etc/resolv.conf 2>> $installLog

if [ -f "/etc/NetworkManager/NetworkManager.conf" ]
then
echo -e "[main]\ndns=default" >> /etc/NetworkManager/NetworkManager.conf 2>> $installLog
fi
fi
installed=true

if [ -f "/etc/systemd/system/dns.service" ]
elif [ -x "/sbin/rc-service" ]
then
echo "Restarting systemd service..."
systemctl restart dns.service >> $installLog 2>&1
else
echo "Configuring systemd service..."
cp $dnsDir/systemd.service /etc/systemd/system/dns.service
systemctl enable dns.service >> $installLog 2>&1

systemctl stop systemd-resolved >> $installLog 2>&1
systemctl disable systemd-resolved >> $installLog 2>&1

systemctl start dns.service >> $installLog 2>&1

rm /etc/resolv.conf >> $installLog 2>&1
echo -e "# Generated by Technitium DNS Server Installer\n\nnameserver 127.0.0.1" > /etc/resolv.conf 2>> $installLog

if [ -f "/etc/NetworkManager/NetworkManager.conf" ]
if [ -f "/etc/init.d/dns" ]
then
echo -e "[main]\ndns=default" >> /etc/NetworkManager/NetworkManager.conf 2>> $installLog
echo "Restarting OpenRC service..."
rc-service dns stop >> $installLog 2>&1
rc-service dns start >> $installLog 2>&1
else
echo "Configuring OpenRC service..."
cp $dnsDir/openrc.service /etc/init.d/dns
chmod +x /etc/init.d/dns
rc-update add dns >> $installLog 2>&1
rc-service dns start >> $installLog 2>&1

rm /etc/resolv.conf >> $installLog 2>&1
echo -e "# Generated by Technitium DNS Server Installer\n\nnameserver 127.0.0.1" > /etc/resolv.conf 2>> $installLog
fi
installed=true
fi

if ! $installed
then
echo "Failed to install Technitium DNS Server: systemd or OpenRC were not detected."
echo "Please read the 'Installing DNS Server Manually' section in this blog post to understand how to manually install the DNS server on your distro: https://blog.technitium.com/2017/11/running-dns-server-on-ubuntu-linux.html"
exit 1
fi

echo ""
Expand Down
8 changes: 8 additions & 0 deletions DnsServerApp/openrc.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/sbin/openrc-run

name=$RC_SVCNAME
description="Technitium DNS Server"
supervisor="supervise-daemon"
command="/usr/bin/dotnet"
command_args="/opt/technitium/dns/DnsServerApp.dll /etc/dns"
supervise_daemon_args=" -d /opt/technitium/dns"