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 # Execute *before* doing anything
# #
if [[ "$(sha1sum discover-routes | cut -f1 -d' ')" == "246d9bbeded14ef58e5bc103af0f8c2e8b2e8cf2" ]]; then if [[ -f discover-routes ]]; then
echo "!!! Rewriting stale 'discover-routes' script" if [[ "$(sha1sum discover-routes | cut -f1 -d' ')" == "246d9bbeded14ef58e5bc103af0f8c2e8b2e8cf2" ]]; then
cp discover-routes.aws.example discover-routes echo "!!! Rewriting stale 'discover-routes' script"
cp discover-routes.aws.example discover-routes
fi
fi fi

View File

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

View File

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

View File

@ -2,8 +2,6 @@
# #
# Execute/teardown on the server side # Execute/teardown on the server side
# #
set -e
if [[ ${#} != 2 ]]; then if [[ ${#} != 2 ]]; then
echo "Usage: ${0} TUNNEL_ID IP_BASE" echo "Usage: ${0} TUNNEL_ID IP_BASE"
exit 1 exit 1
@ -26,6 +24,18 @@ function teardown() {
} }
echo "CONNECTED" 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 done
teardown

View File

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