Add reconnection logic to xaval

This commit is contained in:
Ivan Ilves 2017-07-13 07:34:47 +02:00
parent 20807053a4
commit c285855807
4 changed files with 23 additions and 2 deletions

View File

@ -16,6 +16,10 @@ declare -r XIRINGUITO_PID=${1}
declare -r SSH_PID=${2}
declare -r LOCAL_TUNNEL_ID=${3}
if [[ ${SSH_PID} -eq 0 ]]; then
kill ${XIRINGUITO_PID} &>/dev/null
fi
while [[ $(ps -p ${XIRINGUITO_PID} | wc -l) -eq 2 ]]; do sleep 1; done
if [[ -f /etc/resolv.conf.orig ]]; then

View File

@ -16,6 +16,10 @@ declare -r XIRINGUITO_PID=${1}
declare -r SSH_PID=${2}
declare -r TUNNEL_ID=${3}
if [[ ${SSH_PID} -eq 0 ]]; then
kill ${XIRINGUITO_PID} &>/dev/null
fi
while [[ -d /proc/${XIRINGUITO_PID} ]]; do sleep 1; done
if [[ -f /etc/resolv.conf.orig ]]; then

15
xaval
View File

@ -2,10 +2,13 @@
#
# xaval - xiringuito connection manager
#
[[ "${DEBUG}" == "true" ]] && set -x
set -e
set -o pipefail
declare -r DIR=${HOME}/.xiringuito/profiles; mkdir -p ${DIR}
declare -r RECONNECT_AFTER=5
function print_help(){
cat <<EOF
@ -135,7 +138,17 @@ function connect_profile(){
suicide_on_absent_profile ${PROFILE}
exec $(dirname ${0})/xiringuito $(cat ${DIR}/${PROFILE})
set +e
TRY=true
while [[ ${TRY} == true ]]; do
$(dirname ${0})/xiringuito $(cat ${DIR}/${PROFILE})
if [[ ${?} -eq 0 || ${?} -eq 143 ]]; then
echo "=> Will sleep ${RECONNECT_AFTER} seconds before reconnection..."
sleep ${RECONNECT_AFTER}
else
TRY=false
fi
done
}
function rename_profile(){

View File

@ -116,7 +116,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} -oConnectionAttempts=3 -oConnectTimeout=10 ${SSH_PRIVATE_KEY_OPTS} ${SSH_EXTRA_OPTS}"
declare -r SSH_OPTS="-oLogLevel=${SSH_LOG_LEVEL:-ERROR} -oConnectionAttempts=3 -oConnectTimeout=3 ${SSH_PRIVATE_KEY_OPTS} ${SSH_EXTRA_OPTS}"
if [[ ${KERNEL} == linux ]]; then
declare -r LOCAL_TUNNEL_ID=${TUNNEL_ID}