Add lokinet DNS for systemd-resolved and resolvconf

ubuntu/groovy
Jason Rhinelander 5 years ago
parent 7decc996b5
commit ed7b024cc8

@ -0,0 +1,2 @@
[Resolve]
DNS=127.3.2.1

@ -0,0 +1,53 @@
#!/bin/bash
# Script to invoke resolvconf (if installed) to add/remove lokinet into/from the resolvconf DNS
# server list. This script does not add if any of these are true:
#
# - /sbin/resolvconf does not exist
# - the systemd-resolved service is active
# - the `bind=` entry in the [dns] section of lokinet.ini is commented out
# - a `no-resolvconf=1` item is present in the [dns] section of lokinet.ini
#
# It always attempts to remove if resolvconf is installed (so that commenting out while running,
# then stopping still removes the added entry).
#
# Usage: lokinet-resolvconf {add|remove} /etc/loki/lokinet.ini
set -e
action="$1"
conf="$2"
if [[ ! ("$action" == "add" || "$action" == "remove") || ! -f "$conf" ]]; then
echo "Usage: $0 {add|remove} /path/to/lokinet.ini" >&2
exit 1
fi
if ! [ -x /sbin/resolvconf ]; then
exit 0
fi
if [ -x /bin/systemctl ] && /bin/systemctl --quiet is-active systemd-resolved.service; then
exit 0
fi
if [ "$action" == "add" ]; then
if ! [ -x /sbin/resolvconf ]; then exit 0; fi
lokinet_ns=$(perl -e 'while (<>) {
if ((/^\[dns\]/ ... /^\[/)) {
if (/^bind\s*=\s*(127.*):53\s*$/) {
$ns=$1;
} elsif (/^no-resolvconf\s*=\s*1\s*/) {
exit;
}
}
}
print $ns' "$conf")
if [ -n "$lokinet_ns" ]; then
echo "nameserver $lokinet_ns" | /sbin/resolvconf -a lo.000lokinet
fi
else
/sbin/resolvconf -d lo.000lokinet
fi

@ -0,0 +1,2 @@
debian/00-lokinet.conf /etc/systemd/resolved.conf.d
debian/lokinet-resolvconf /usr/sbin

@ -8,6 +8,8 @@ User=_lokinet
SyslogIdentifier=lokinet
RequireFileExists=/var/lib/lokinet/bootstrap.signed
ExecStart=/usr/bin/lokinet /var/lib/lokinet/lokinet.ini
ExecStartPost=+/usr/sbin/lokinet-resolvconf add /var/lib/lokinet/lokinet.ini
ExecStopPost=+/usr/sbin/lokinet-resolvconf remove /var/lib/lokinet/lokinet.ini
Restart=always
[Install]

4
debian/postinst vendored

@ -45,6 +45,10 @@ if [ "$1" = configure ]; then
ucf $tmpdir/lokinet.ini /etc/loki/lokinet.ini
ucfr lokinet /etc/loki/lokinet.ini
if [ -x /bin/systemctl ] && /bin/systemctl --quiet is-active systemd-resolved.service; then
/bin/systemctl restart systemd-resolved.service
fi
fi
#DEBHELPER#

Loading…
Cancel
Save