Commit 1ed0a6a2 authored by kytv's avatar kytv Committed by kytv

Restart Tor if bootstrapping stalls for more than 20 seconds

Will-fix: #9516
parent a3f66357
......@@ -175,7 +175,7 @@ maybe_set_time_from_tor_consensus() {
date -us "${vmid}" 1>/dev/null
# Tor is unreliable with picking a circuit after time change
restart-tor
service tor restart
}
tor_cert_valid_after() {
......
......@@ -2,13 +2,52 @@
set -e
# Import try_for()
. /usr/local/lib/tails-shell-library/common.sh
# Import tor_bootstrap_progress()
. /usr/local/lib/tails-shell-library/tor.sh
# The Tor log is removed to ensure `tor_bootstrap_progress`'s output will be
# accurate.
clear_tor_log() {
rm -f /var/log/tor/log
}
clear_tor_log
service tor restart
# The main point of this script is to make sure that if vidalia is
# running, and Tor is restarted, then we also restart Vidalia. This is
# because Vidalia doesn't re-connect to Tor automatically, so the user
# has to restart it to be able to control Tor again. Also, any options
# set by Vidalia will be lost since they weren't written to torrc.
# There are two main points to this script:
# * restarting Tor if bootstrapping stalls for more than 20 seconds
# * making sure that if vidalia is running it is restarted if Tor is restarted.
# This is needed because Vidalia doesn't re-connect to Tor automatically,
# so the user has to restart it to be able to control Tor again. Also, any
# options set by Vidalia will be lost since they weren't written to torrc.
bootstrap_progress=0
last_bootstrap_change=$(date +%s)
maybe_restart_tor() {
local new_bootstrap_progress=$(tor_bootstrap_progress)
if [ $new_bootstrap_progress -eq 100 ]; then
return 0
elif [ $new_bootstrap_progress -gt $bootstrap_progress ]; then
bootstrap_progress=$new_bootstrap_progress
last_bootstrap_change=$(date +%s)
return 1
elif [ $(expr $(date +%s) - $last_bootstrap_change) -ge 20 ]; then
clear_tor_log
service tor restart
bootstrap_progress=0
last_bootstrap_change=$(date +%s)
return 1
else
return 1
fi
}
try_for 270 maybe_restart_tor
if pgrep "\<vidalia\>" >/dev/null; then
killall -SIGKILL vidalia
# Since Tor just restarted we wait for a while until the
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment