From 89a254cd79c0eb524ce6dd3b7a67cc8879bad5fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs?= Date: Wed, 28 Jul 2021 22:25:46 -0500 Subject: separate TOR configuration --- core/Dockerfile | 2 ++ core/entrypoint-tor.sh | 22 ++++++++++++++++++++++ core/entrypoint.sh | 30 +++--------------------------- 3 files changed, 27 insertions(+), 27 deletions(-) create mode 100644 core/entrypoint-tor.sh diff --git a/core/Dockerfile b/core/Dockerfile index e9fd4a3..55c196d 100644 --- a/core/Dockerfile +++ b/core/Dockerfile @@ -27,7 +27,9 @@ RUN apk del build-base patch python3-dev EXPOSE 8080 +COPY entrypoint-tor.sh / COPY entrypoint.sh / +RUN chmod u+x /entrypoint-tor.sh RUN chmod u+x /entrypoint.sh ENTRYPOINT ["/entrypoint.sh"] diff --git a/core/entrypoint-tor.sh b/core/entrypoint-tor.sh new file mode 100644 index 0000000..7c1e42f --- /dev/null +++ b/core/entrypoint-tor.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env sh + +if [ "$ROUTE_TOR" = 1 ] || [ "$ROUTE_TOR" = 2 ]; then + cat > /etc/tor/torrc <<- EOF +Log notice stdout +SocksPort ${TOR_PORT:-9050} # Default: Bind to localhost:9050 for local connections. +MaxCircuitDirtiness ${MAX_CIRCUIT:-300} +CircuitBuildTimeout ${CIRCUIT_TIMEOUT:-300} +ExcludeExitNodes {US} +StrictNodes 1 +EOF + tor -f /etc/tor/torrc --runasdaemon 1 + + # check loop health tor + while :; do + checkurl=$(curl --socks5 "localhost:${TOR_PORT:-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 1 + fi + sleep 5 + done +fi diff --git a/core/entrypoint.sh b/core/entrypoint.sh index 5596bbd..c27698a 100644 --- a/core/entrypoint.sh +++ b/core/entrypoint.sh @@ -77,30 +77,6 @@ settings_version = 3 EOF fi -if [ "$ROUTE_TOR" = 1 ] || [ "$ROUTE_TOR" = 2 ]; then - cat > /etc/tor/torrc <<- EOF -Log notice stdout -SocksPort ${TOR_PORT:-9050} # Default: Bind to localhost:9050 for local connections. -MaxCircuitDirtiness ${MAX_CIRCUIT:-300} -CircuitBuildTimeout ${CIRCUIT_TIMEOUT:-300} -ExcludeExitNodes {US} -StrictNodes 1 -EOF - tor -f /etc/tor/torrc --runasdaemon 1 - - # check health tor - while :; do - checkurl=$(curl --socks5 "localhost:${TOR_PORT:-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 1 - pkill python3 || true - /usr/bin/python3 /srv/app/server.py || true - else - pgrep python3 > /dev/null || /usr/bin/python3 /srv/app/server.py - fi - sleep 5 - done - -else - exec /usr/bin/python3 /srv/app/server.py -fi +/entrypoint-tor.sh "$@" & + +exec /usr/bin/python3 /srv/app/server.py -- cgit v1.2.3