aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesús <heckyel@hyperbola.info>2021-07-28 20:16:32 -0500
committerJesús <heckyel@hyperbola.info>2021-07-28 20:16:32 -0500
commitfade4534246627375a2c7fe11fdb0843ccb449e1 (patch)
tree8ef8af7287cfed2372207d799ff557f61733b276
parent5f07a8a46f42f78523272d43670c7787a1de5227 (diff)
downloadyt-local-docker-fade4534246627375a2c7fe11fdb0843ccb449e1.tar.lz
yt-local-docker-fade4534246627375a2c7fe11fdb0843ccb449e1.tar.xz
yt-local-docker-fade4534246627375a2c7fe11fdb0843ccb449e1.zip
check health with tor is blocked
-rw-r--r--config.env.example6
-rw-r--r--core/Dockerfile2
-rw-r--r--core/entrypoint.sh17
3 files changed, 22 insertions, 3 deletions
diff --git a/config.env.example b/config.env.example
index 20ecacf..d32e42b 100644
--- a/config.env.example
+++ b/config.env.example
@@ -41,3 +41,9 @@ DEBUGGING_SAVE_RESPONSES=False
MAX_CIRCUIT=500 # seconds
CIRCUIT_TIMEOUT=500 # seconds
+
+#
+# Health TOR check
+#
+
+URL_CHECK=https://www.youtube.com/results?search_query=rms
diff --git a/core/Dockerfile b/core/Dockerfile
index b07f525..e9fd4a3 100644
--- a/core/Dockerfile
+++ b/core/Dockerfile
@@ -4,7 +4,7 @@ LABEL MAINTAINER="heckyel@riseup.net"
ENV LANG C.UTF-8
ENV LC_ALL C.UTF-8
-RUN apk add --no-cache musl-dev build-base gcc libffi-dev python3-dev patch git py3-pip tor
+RUN apk add --no-cache musl-dev build-base gcc libffi-dev python3-dev patch git py3-pip tor curl
ARG APP_DIR="/srv/app"
ARG YT_REPO="https://git.sr.ht/~heckyel/yt-local"
diff --git a/core/entrypoint.sh b/core/entrypoint.sh
index bbe05d6..47c4dd1 100644
--- a/core/entrypoint.sh
+++ b/core/entrypoint.sh
@@ -87,6 +87,19 @@ ExcludeExitNodes {US}
StrictNodes 1
EOF
tor -f /etc/tor/torrc --runasdaemon 1
-fi
-exec /usr/bin/python3 /srv/app/server.py
+ # check health tor
+ while :; do
+ checkurl=$(curl --socks5 localhost:9050 -o /dev/null -s -w "%{http_code}\n" "${URL_CHECK:-https://www.youtube.com/results?search_query=rms}")
+ if [ "$checkurl" = '502' ] || [ "$checkurl" = '302' ]; then
+ pkill tor && tor -f /etc/tor/torrc --runasdaemon 0 2>&1
+ pkill python3 && /usr/bin/python3 /srv/app/server.py
+ else
+ pgrep python3 > /dev/null || exec /usr/bin/python3 /srv/app/server.py
+ fi
+ sleep 5
+ done
+
+else
+ exec /usr/bin/python3 /srv/app/server.py
+fi