separate TOR configuration

This commit is contained in:
Jesús 2021-07-28 22:25:46 -05:00
parent c826d1c7b5
commit 89a254cd79
No known key found for this signature in database
GPG Key ID: F6EE7BC59A315766
3 changed files with 26 additions and 26 deletions

View File

@ -27,7 +27,9 @@ RUN apk del build-base patch python3-dev
EXPOSE 8080 EXPOSE 8080
COPY entrypoint-tor.sh /
COPY entrypoint.sh / COPY entrypoint.sh /
RUN chmod u+x /entrypoint-tor.sh
RUN chmod u+x /entrypoint.sh RUN chmod u+x /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"] ENTRYPOINT ["/entrypoint.sh"]

22
core/entrypoint-tor.sh Normal file
View File

@ -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

View File

@ -77,30 +77,6 @@ settings_version = 3
EOF EOF
fi fi
if [ "$ROUTE_TOR" = 1 ] || [ "$ROUTE_TOR" = 2 ]; then /entrypoint-tor.sh "$@" &
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 exec /usr/bin/python3 /srv/app/server.py
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