-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pull request 1779: 3290-docker-healthcheck
Merge in DNS/adguard-home from 3290-docker-healthcheck to master Updates #3290. Squashed commit of the following: commit 3ac8f26 Merge: bc17565 0df3260 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Mon Mar 27 01:09:03 2023 +0500 Merge branch 'master' into 3290-docker-healthcheck commit bc17565 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Sun Mar 26 18:04:08 2023 +0500 all: fix script commit e150fee Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Sun Mar 26 17:18:12 2023 +0500 all: imp naming commit 26b6448 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Sun Mar 26 03:13:47 2023 +0500 all: support https web commit b5c09ce Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Sat Mar 25 20:03:45 2023 +0500 all: imp scripts fmt, naming commit 8c3798c Merge: e33b0c5 fb7b8bb Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Sat Mar 25 00:25:38 2023 +0500 Merge branch 'master' into 3290-docker-healthcheck commit e33b0c5 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Fri Mar 24 16:47:26 2023 +0500 all: fix docs commit 57bfd89 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Fri Mar 24 16:44:40 2023 +0500 dnsforward: add special-use domain handling commit f04ae13 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Fri Mar 24 16:05:10 2023 +0500 all: imp code commit 32f150f Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Fri Mar 24 04:19:10 2023 +0500 all: mv Dockerfile, log changes commit a094a44 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Fri Mar 24 04:04:27 2023 +0500 all: finish scripts, imp names commit 4db0d0e Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Mar 23 18:33:47 2023 +0500 docker: add script and awk program
- Loading branch information
1 parent
0df3260
commit d58772f
Showing
8 changed files
with
167 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/^[^[:space:]]/ { is_dns = /^dns:/ } | ||
|
||
/^[[:space:]]+bind_hosts:/ { if (is_dns) prev_line = FNR } | ||
|
||
/^[[:space:]]+- .+/ { | ||
if (FNR - prev_line == 1) { | ||
addrs[addrsnum++] = $2 | ||
prev_line = FNR | ||
} | ||
} | ||
|
||
/^[[:space:]]+port:/ { if (is_dns) port = $2 } | ||
|
||
END { | ||
for (i in addrs) { | ||
if (match(addrs[i], ":")) { | ||
print "[" addrs[i] "]:" port | ||
} else { | ||
print addrs[i] ":" port | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
#!/bin/sh | ||
|
||
# AdGuard Home Docker healthcheck script | ||
|
||
# Exit the script if a pipeline fails (-e), prevent accidental filename | ||
# expansion (-f), and consider undefined variables as errors (-u). | ||
set -e -f -u | ||
|
||
# Function error_exit is an echo wrapper that writes to stderr and stops the | ||
# script execution with code 1. | ||
error_exit() { | ||
echo "$1" 1>&2 | ||
|
||
exit 1 | ||
} | ||
|
||
agh_dir="/opt/adguardhome" | ||
readonly agh_dir | ||
|
||
filename="${agh_dir}/conf/AdGuardHome.yaml" | ||
readonly filename | ||
|
||
if ! [ -f "$filename" ] | ||
then | ||
wget "http://127.0.0.1:3000" -O /dev/null -q || exit 1 | ||
|
||
exit 0 | ||
fi | ||
|
||
help_dir="${agh_dir}/scripts" | ||
readonly help_dir | ||
|
||
# Parse web host | ||
|
||
web_url="$( awk -f "${help_dir}/web-bind.awk" "$filename" )" | ||
readonly web_url | ||
|
||
if [ "$web_url" = '' ] | ||
then | ||
error_exit "no web bindings could be retrieved from $filename" | ||
fi | ||
|
||
# TODO(e.burkov): Deal with 0 port. | ||
case "$web_url" | ||
in | ||
(*':0') | ||
error_exit '0 in web port is not supported by healthcheck' | ||
;; | ||
(*) | ||
# Go on. | ||
;; | ||
esac | ||
|
||
# Parse DNS hosts | ||
|
||
dns_hosts="$( awk -f "${help_dir}/dns-bind.awk" "$filename" )" | ||
readonly dns_hosts | ||
|
||
if [ "$dns_hosts" = '' ] | ||
then | ||
error_exit "no DNS bindings could be retrieved from $filename" | ||
fi | ||
|
||
# TODO(e.burkov): Deal with 0 port. | ||
case "$( echo "$dns_hosts" | head -n 1 )" | ||
in | ||
(*':0') | ||
error_exit '0 in DNS port is not supported by healthcheck' | ||
;; | ||
(*) | ||
# Go on. | ||
;; | ||
esac | ||
|
||
# Check | ||
|
||
wget "$web_url" -O /dev/null -q || exit 1 | ||
|
||
echo "$dns_hosts" | while read -r host | ||
do | ||
nslookup -type=a healthcheck.adguardhome.test. "$host" > /dev/null ||\ | ||
error_exit "nslookup failed for $host" | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
BEGIN { scheme = "http" } | ||
|
||
/^bind_host:/ { host = $2 } | ||
|
||
/^bind_port:/ { port = $2 } | ||
|
||
/force_https: true$/ { scheme = "https" } | ||
|
||
/port_https:/ { https_port = $2 } | ||
|
||
/server_name:/ { https_host = $2 } | ||
|
||
END { | ||
if (scheme == "https") { | ||
host = https_host | ||
port = https_port | ||
} | ||
if (match(host, ":")) { | ||
print scheme "://[" host "]:" port | ||
} else { | ||
print scheme "://" host ":" port | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters