Add reconnection functionality

This commit is contained in:
Ivan Ilves 2017-04-09 11:24:27 +02:00
parent 3808955f85
commit 047a457a2f
2 changed files with 11 additions and 3 deletions

View File

@ -26,7 +26,7 @@ function teardown() {
echo "CONNECTED"
FAILED_PINGS=0
while [[ ${FAILED_PINGS} -lt 20 ]]; do
while [[ ${FAILED_PINGS} -lt 10 ]]; do
ping -c3 -nq ${CLIENT_IP_ADDR} >/dev/null
if [[ ${?} -ne 0 ]]; then
let FAILED_PINGS+=1

View File

@ -33,6 +33,10 @@ if [[ ${#} -lt 1 ]]; then
exit 1
fi
# We need to save executable path and arguments for reconnection functionality
declare -r ORIGINAL_EXEC=${0}
declare -r ORIGINAL_ARGS=${@}
while getopts "RDh" o; do
case ${o} in
R)
@ -151,8 +155,8 @@ fi
set +e
FAILED_PINGS=0
while [[ ${FAILED_PINGS} -lt 20 ]]; do
kill -0 ${SSH_PID} &>/dev/null || exit 17
while [[ ${FAILED_PINGS} -lt 10 ]]; do
kill -0 ${SSH_PID} &>/dev/null || break
./scripts/client-ping-server.sh ${TUNNEL_ID} ${IP_BASE}
if [[ ${?} -ne 0 ]]; then
@ -166,3 +170,7 @@ while [[ ${FAILED_PINGS} -lt 20 ]]; do
done
teardown
if [[ -z "${NO_RECONNECT}" ]]; then
exec ${ORIGINAL_EXEC} ${ORIGINAL_ARGS}
fi