Skip to content

Commit

Permalink
Merge pull request #66 from ivanilves/ISSUE-65
Browse files Browse the repository at this point in the history
Report errors better and wait for connection to become up
  • Loading branch information
vonrabbe authored Nov 17, 2018
2 parents cfbb3f3 + 5c0ff25 commit beaee21
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
4 changes: 2 additions & 2 deletions scripts/bootstrap-server-sudo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 changes: 35 additions & 0 deletions xaval
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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() {
Expand All @@ -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}
Expand Down

0 comments on commit beaee21

Please sign in to comment.