Merge pull request #20 from ivanilves/feature/better-teardown

Better teardown FTW!
This commit is contained in:
Ivan Ilves 2017-04-02 19:52:20 +02:00 committed by GitHub
commit 4401aec84d
5 changed files with 33 additions and 19 deletions

View File

@ -2,7 +2,9 @@
#
# Execute *before* doing anything
#
if [[ "$(sha1sum discover-routes | cut -f1 -d' ')" == "246d9bbeded14ef58e5bc103af0f8c2e8b2e8cf2" ]]; then
echo "!!! Rewriting stale 'discover-routes' script"
cp discover-routes.aws.example discover-routes
if [[ -f discover-routes ]]; then
if [[ "$(sha1sum discover-routes | cut -f1 -d' ')" == "246d9bbeded14ef58e5bc103af0f8c2e8b2e8cf2" ]]; then
echo "!!! Rewriting stale 'discover-routes' script"
cp discover-routes.aws.example discover-routes
fi
fi

View File

@ -23,7 +23,7 @@ if [[ -f /etc/resolv.conf.orig ]]; then
fi
if [[ ${SSH_PID} -ne 0 ]]; then
kill ${SSH_PID}; sleep 1
kill ${SSH_PID} &>/dev/null; sleep 1
fi
NETWORK_SERVICE="$($(dirname ${0})/get-network-service-name.sh)"

View File

@ -23,7 +23,7 @@ if [[ -f /etc/resolv.conf.orig ]]; then
fi
if [[ ${SSH_PID} -ne 0 ]]; then
kill ${SSH_PID}; sleep 1
kill ${SSH_PID} &>/dev/null; sleep 1
fi
ip tuntap del mode tun tun${TUNNEL_ID}

View File

@ -2,8 +2,6 @@
#
# Execute/teardown on the server side
#
set -e
if [[ ${#} != 2 ]]; then
echo "Usage: ${0} TUNNEL_ID IP_BASE"
exit 1
@ -26,6 +24,18 @@ function teardown() {
}
echo "CONNECTED"
while true; do
sleep 60000 # TODO: Maybe we need some heartbeat here
FAILED_PINGS=0
while [[ ${FAILED_PINGS} -lt 5 ]]; do
ping -c3 -nq ${CLIENT_IP_ADDR} >/dev/null
if [[ ${?} -ne 0 ]]; then
let FAILED_PINGS+=1
logger -i -p warn "xiringuito[${TUNNEL_ID}]: Failed to ping ${CLIENT_IP_ADDR} (${FAILED_PINGS})"
else
FAILED_PINGS=0
fi
sleep 5
done
teardown

View File

@ -50,7 +50,7 @@ fi
declare -r TUNNEL_ID=$(cat ${TUNNEL_ID_FILE})
declare -r REMOTE_PATH="/tmp/xiringuito.${TUNNEL_ID}"
declare -r SSH_OPTS="-oLogLevel=${SSH_LOG_LEVEL:-ERROR} -oConnectTimeout=10"
declare -r SSH_OPTS="-oLogLevel=${SSH_LOG_LEVEL:-ERROR} -oConnectionAttempts=3 -oConnectTimeout=10"
if [[ ${KERNEL} == linux ]]; then
declare -r LOCAL_TUNNEL_ID=${TUNNEL_ID}
@ -62,9 +62,7 @@ trap 'exit 130' INT
trap teardown EXIT
function teardown() {
if [[ ${SSH_PID} ]]; then
ssh ${SSH_OPTS} ${SSH_SERVER} pkill -f ${REMOTE_PATH}/server-execute.sh &>/dev/null &
else
if [[ ! ${SSH_PID} ]]; then
sudo ./scripts/${KERNEL}/client-teardown.sh ${$} 0 ${LOCAL_TUNNEL_ID}
fi
}
@ -122,13 +120,17 @@ if [[ ! ${NO_DNS} && ! -z "${NETWORKS}" ]]; then
fi
set +e
while true; do
if [[ ! ${NO_PING} ]]; then
./scripts/client-ping-server.sh ${TUNNEL_ID} ${IP_BASE}
if [[ ${?} -ne 0 ]]; then
echo "* Failed to ping server-side tunnel endpoint..."
fi
FAILED_PINGS=0
while [[ ${FAILED_PINGS} -lt 5 ]]; do
./scripts/client-ping-server.sh ${TUNNEL_ID} ${IP_BASE}
if [[ ${?} -ne 0 ]]; then
let FAILED_PINGS+=1
echo "* Failed to ping server-side tunnel endpoint... (${FAILED_PINGS})"
else
FAILED_PINGS=0
fi
sleep 5
done
teardown