Merge pull request #66 from ivanilves/ISSUE-65

Report errors better and wait for connection to become up
This commit is contained in:
Clauss von Rabbe Jr 2018-11-17 07:49:20 +01:00 committed by GitHub
commit beaee21a0b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 2 deletions

View File

@ -2,7 +2,7 @@
#
# Bootstrap sudoers.d config on server side before doing anything else!
#
set -e
set -eo pipefail
if [[ ${#} -lt 1 ]]; then
echo "Usage: ${0} [OPTIONS] [SSH_USER@]SSH_SERVER"
@ -17,4 +17,4 @@ declare -r STDOUTERR=/tmp/xiringuito.$(basename ${0}).${USER}
ssh -t -oStrictHostKeyChecking=no ${@} \
"sudo true && sudo bash -c \
\"umask 0337 && echo -e ${SUDO_NOTE}'\n'\${USER} ${SUDO_CONF} | tee ${BASE_NAME}-\${USER}\" >/dev/null" \
&>${STDOUTERR}
&>${STDOUTERR} || (cat ${STDOUTERR} >>/dev/stderr && exit 1)

35
xaval
View File

@ -11,6 +11,7 @@ declare -r ROOT_DIR=${HOME}/.xiringuito
declare -r DIR=${ROOT_DIR}/profiles; mkdir -p ${DIR}
declare -r LOG_DIR=${ROOT_DIR}/logs; mkdir -p ${LOG_DIR}
declare -r RECONNECT_AFTER=5
declare -r WAIT_TIMEOUT=15
declare -r ATTACH_MARKER="${ROOT_DIR}/attach"
if [[ -f "${ATTACH_MARKER}" ]]; then
@ -258,6 +259,28 @@ function connect_profile(){
echo
echo "Use \"xaval logs ${PROFILE}\" to see connection logs"
loop_connection ${PROFILE} &>${LOG_FILE} &
wait_connection ${PROFILE}
}
function wait_connection(){
local PROFILE=${1}
sleep 2
local WAIT_TIME=0
while [[ "$(get_profile_status ${PROFILE})" != "UP" ]]; do
if [[ ${WAIT_TIME} -ge ${WAIT_TIMEOUT} ]]; then
dump_profile_log ${PROFILE}
commit_suicide "Unable to bring up \"${PROFILE}\" after ${WAIT_TIMEOUT} seconds"
fi
echo "* Waiting for connection to come up..."
sleep 1
((++WAIT_TIME))
done
}
function kill_profile() {
@ -282,6 +305,18 @@ function logs_profile() {
echo "STATUS: $(get_profile_status ${PROFILE})"
}
function dump_profile_log() {
local PROFILE=${1}
suicide_on_absent_profile ${PROFILE}
local LOG_FILE=${LOG_DIR}/${PROFILE}
echo "--- LOG ---" >>/dev/stderr
cat ${LOG_FILE} >>/dev/stderr
echo "--- LOG ---" >>/dev/stderr
}
function rename_profile(){
local OLD_PROFILE=${1}
local NEW_PROFILE=${2}