Skip to content

Commit

Permalink
šŸ— Capture console output and verbose logging during sauce connect faiā€¦
Browse files Browse the repository at this point in the history
ā€¦lures (#20729)
  • Loading branch information
rsimha authored Feb 7, 2019
1 parent 09b9848 commit 7d695c0
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions build-system/sauce_connect/start_sauce_connect.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ TAR_FILE="$DOWNLOAD_DIR/$SC_VERSION.tar.gz"
BINARY_FILE="$SC_VERSION/bin/sc"
PID_FILE="sauce_connect_pid"
LOG_FILE="sauce_connect_log"
OUTPUT_FILE="sauce_connect_output"
READY_FILE="sauce_connect_ready"
READY_DELAY_SECS=120
LOG_PREFIX=$(YELLOW "start_sauce_connect.sh")
Expand Down Expand Up @@ -63,7 +64,7 @@ fi
echo "$LOG_PREFIX Unpacking $(CYAN "$TAR_FILE")"
tar -xzf "$TAR_FILE"

# Clean up old log files, if any.
# Clean up old files, if any.
if [[ -f "$LOG_FILE" ]]; then
echo "$LOG_PREFIX Deleting old log file $(CYAN "$LOG_FILE")"
rm "$LOG_FILE"
Expand All @@ -72,6 +73,10 @@ if [[ -f $PID_FILE ]]; then
echo "$LOG_PREFIX Deleting old pid file $(CYAN "$PID_FILE")"
rm "$PID_FILE"
fi
if [[ -f "$OUTPUT_FILE" ]]; then
echo "$LOG_PREFIX Deleting old output file $(CYAN "$OUTPUT_FILE")"
rm "$OUTPUT_FILE"
fi

# Establish the tunnel identifier (job number on Travis / username during local dev).
if [[ -z "$TRAVIS_JOB_NUMBER" ]]; then
Expand All @@ -82,15 +87,15 @@ fi

# Launch proxy and wait for a tunnel to be created.
echo "$LOG_PREFIX Launching $(CYAN "$BINARY_FILE")"
"$BINARY_FILE" --verbose --tunnel-identifier "$TUNNEL_IDENTIFIER" --readyfile "$READY_FILE" --pidfile "$PID_FILE" 1>"$LOG_FILE" 2>&1 &
"$BINARY_FILE" --verbose --tunnel-identifier "$TUNNEL_IDENTIFIER" --readyfile "$READY_FILE" --pidfile "$PID_FILE" --logfile "$LOG_FILE" 1>"$OUTPUT_FILE" 2>&1 &
count=0
while [ $count -lt $READY_DELAY_SECS ]
do
if [ -e "$READY_FILE" ]
then
# Print confirmation.
PID="$(cat "$PID_FILE")"
TUNNEL_ID="$(grep -oP "Tunnel ID: \K.*$" "$LOG_FILE")"
TUNNEL_ID="$(grep -oP "Tunnel ID: \K.*$" "$OUTPUT_FILE")"
echo "$LOG_PREFIX Sauce Connect Proxy with tunnel ID $(CYAN "$TUNNEL_ID") and identifier $(CYAN "$TUNNEL_IDENTIFIER") is now running as pid $(CYAN "$PID")"
break
else
Expand All @@ -101,6 +106,8 @@ do
then
# Print the error logs.
echo "$LOG_PREFIX Sauce Connect Proxy has not started after $(CYAN "$READY_DELAY_SECS") seconds."
echo "$LOG_PREFIX Console output:"
cat "$OUTPUT_FILE"
echo "$LOG_PREFIX Log file contents:"
cat "$LOG_FILE"
exit 1
Expand Down

0 comments on commit 7d695c0

Please sign in to comment.