client: plugins: tor: implement retries when bootstrapping
This commit is contained in:
@@ -102,12 +102,25 @@ function tor::start()
|
||||
local -r _sleep="30s"
|
||||
lib_utils::print_info "${global_container}: testing connection (bootstrapping ~${_sleep})"
|
||||
sleep "$_sleep" # Give time to bootstrap
|
||||
# TODO: run timer to verify response (and fail if N times if no response)
|
||||
docker exec "$global_container" \
|
||||
/bin/bash -i -c "
|
||||
proxychains curl -s https://check.torproject.org 2>/dev/null \
|
||||
|
||||
local _tries=1
|
||||
while [ $_tries -ne 3 ]; do
|
||||
lib_docker::exec "proxychains curl -s https://check.torproject.org 2>/dev/null \
|
||||
| grep -B3 'Your IP address appears to be' \
|
||||
| sed -e 's/^ //g' -e '\$ s/[^\\.0-9]//g' -e '/^\$/d' -e '2,3d'" || lib_utils::die_fatal
|
||||
| sed -e 's/^ //g' -e '\$ s/[^\\.0-9]//g' -e '/^\$/d' -e '2,3d' \
|
||||
| grep -A2 --color=never Congratulations || exit 1 2>/dev/null" 2>/dev/null
|
||||
if [ $? -ne 0 ]; then
|
||||
lib_utils::print_warning "Could not bootstrap, trying again (${_tries}/3)"
|
||||
docker exec "$tor_container" /bin/sh -c "pkill -HUP tor" || lib_utils::die_fatal
|
||||
sleep "$_sleep"
|
||||
((_tries++))
|
||||
else
|
||||
break
|
||||
fi
|
||||
done
|
||||
if [ $_tries -eq 3 ]; then
|
||||
lib_utils::die_fatal "Could not successfully bootstrap! \`restart\` this instance"
|
||||
fi
|
||||
}
|
||||
|
||||
function tor::stop()
|
||||
|
||||
Reference in New Issue
Block a user