Skip to content

Instantly share code, notes, and snippets.

@mehmetg
Last active October 25, 2016 13:44
Show Gist options
  • Save mehmetg/20c2a0f9df25424e130a to your computer and use it in GitHub Desktop.
Save mehmetg/20c2a0f9df25424e130a to your computer and use it in GitHub Desktop.
Starts 5 SC instances for round robin load balancing and 1 for command relay. Relies on https://gist.github.com/mehmetg/9cdc77269ddef72ebc84
#!/usr/bin/env bash
#This script is intended to be run from the root of the sauce connect package.
SCBIN="bin/sc"
uname=$1
akey=$2
uname="user name"
akey="access key"
LOGPREFIX="/tmp"
function start_sauce_connect() {
tunnelId=$1
if [ -z "$2" ]; then
port="4445"
else
port=$2
fi
echo "tunnel id: ${tunnelId}"
echo "se port: ${port}"
args="--user ${uname} \
--api-key ${akey} \
--max-logsize 524288000 \
--se-port ${port} \
--logfile ${LOGPREFIX}/sc_log_${tunnelId}_${port}.log \
--pidfile ${LOGPREFIX}/sc_${tunnelId}_${port}.pid \
--readyfile ${LOGPREFIX}/sc_${tunnelId}_${port}.rdy \
--no-remove-colliding-tunnels \
--wait-tunnel-shutdown \
--daemonize"
if ! [ -z "$tunnelId" ]; then
args="${args} --tunnel-identifier ${tunnelId}"
fi
echo $SCBIN $args
$SCBIN $args
}
function is_tunnel_ready() {
tunnelId=$1
if [ -z "$2" ]; then
port="4445"
else
port=$2
fi
ready_file="${LOGPREFIX}/sc_${tunnelId}_${port}.rdy"
ctr=0
while ! [[ -e "$ready_file" ]] && [[ $ctr -lt 10 ]];
do
echo "Waiting ${ctr}"
echo "se port: ${port}"
echo "tunnel id: ${tunnelId}"
sleep 3
let ctr=ctr+1
done
if [[ ctr -gt 9 ]]; then
echo "Failed:"
echo "se port: ${port}"
echo "tunnel id: ${tunnelId}"
else
echo "Ready:"
echo "se port: ${port}"
echo "tunnel id: ${tunnelId}"
fi
}
if ! [ -z "$uname" ]; then
# echo $uname
export SAUCE_USERNAME=$uname
echo "Username supplied!"
else
echo "No username supplied"
exit 1
fi
if ! [ -z "$akey" ]; then
# echo $akey
export SAUCE_ACCESS_KEY=$akey
echo "Access key supplied!"
else
echo "No access key supplied"
exit 1
fi
./stop_sc.sh
rm -rf ${LOGPREFIX}/sc*
#relay only
start_sauce_connect "command_relay_only" "4445"
is_tunnel_ready "command_relay_only" "4445"
for p in `seq 4446 4450`;
do
start_sauce_connect "" $p
sleep 1
done
for p in `seq 4446 4450`;
do
is_tunnel_ready "" $p
sleep 1
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment