From 72e5499ab947768f3fd89397535b85f940cb9ebf Mon Sep 17 00:00:00 2001 From: f Date: Thu, 1 Apr 2021 15:49:14 -0300 Subject: [PATCH] autonomous dns --- Dockerfile | 20 ++++++++++---------- monitrc | 5 +++++ nsupdate.sh | 22 ++++++++++++++++++++++ whatsmyip6.sh | 3 +++ 4 files changed, 40 insertions(+), 10 deletions(-) create mode 100755 nsupdate.sh create mode 100755 whatsmyip6.sh diff --git a/Dockerfile b/Dockerfile index 19e1bf6..a6ba075 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM alpine:3.13.2 AS build +FROM alpine:3.13.3 AS build ENV EMAIL monit@sutty.nl RUN apk add --no-cache tzdata @@ -7,33 +7,33 @@ COPY ./monitrc /etc/monitrc RUN chmod 600 /etc/monitrc RUN sed -re "s/@@EMAIL@@/${EMAIL}/" -i /etc/monitrc -FROM alpine:3.13.2 +FROM alpine:3.13.3 MAINTAINER "f " # TODO: We don't want to receive lots of email, so we'll change this to # a pingy instance that will also work as a status site. ENV EMAIL monit@sutty.nl +# Sutty's repository +RUN echo https://alpine.sutty.nl/alpine/v3.13/sutty >> /etc/apk/repositories +RUN wget https://alpine.sutty.nl/alpine/sutty.pub -O /etc/apk/keys/alpine@sutty.nl-5ea884cd.rsa.pub + # Install monit and remove default config -RUN apk upgrade --no-cache -RUN apk add --no-cache tini monit +RUN apk add --no-cache tini monit knsupdate COPY --from=build /usr/share/zoneinfo/UTC /etc/localtime # Create directories RUN install -dm 2750 -o root -g root /etc/monit.d RUN install -dm 2750 -o root -g root /var/lib/monit -# Install config. monit.conf~ will be activated after allow_networks -# runs. +# Install config COPY --from=build /etc/monitrc /etc/monitrc +COPY ./nsupdate.sh /usr/local/bin/nsupdate +COPY ./whatsmyip6.sh /usr/local/bin/whatsmyip6 # Allow access to the web GUI EXPOSE 2812 -# Sutty's repository -RUN echo 'https://alpine.sutty.nl/alpine/v3.13/sutty' >> /etc/apk/repositories -RUN wget https://alpine.sutty.nl/alpine/sutty.pub -O /etc/apk/keys/alpine@sutty.nl-5ea884cd.rsa.pub - # Use tini as init ENTRYPOINT ["/sbin/tini", "--"] diff --git a/monitrc b/monitrc index 9ec502d..80a42f4 100644 --- a/monitrc +++ b/monitrc @@ -13,4 +13,9 @@ set httpd port 2812 allow localhost allow 172.0.0.0/8 +check program nsupdate + with path "/usr/local/bin/nsupdate" + every 1 cycle + if status = 0 then unmonitor + include /etc/monit.d/*.conf diff --git a/nsupdate.sh b/nsupdate.sh new file mode 100755 index 0000000..2d3b705 --- /dev/null +++ b/nsupdate.sh @@ -0,0 +1,22 @@ +#!/bin/sh + +# Registers the local IPv6 address to the DNS + +IP6="`whatsmyip6`" +KNOT="${KNOT:-${IP6}}" + +test -z "${IP6}" && exit 1 +test -z "${KNOT}" && exit 1 +test -z "${DOMAIN}" && exit 1 + +knsupdate <