Skip to content

Instantly share code, notes, and snippets.

Last active March 25, 2016 21:04
Show Gist options
  • Save santiycr/7b57300ebfd3b9fc508f to your computer and use it in GitHub Desktop.
Save santiycr/7b57300ebfd3b9fc508f to your computer and use it in GitHub Desktop.
# Restart SauceConnect via Rolling Restart
# The port it uses for listening for Selenium Relay
# is chosen automatically an ranges between 4441 and 4449
# Tunnel identifiers are optional, but removing them
# from this example would include some tweaking
for POTENTIAL_PORT in {1..9};
curl -q "http://localhost:${NEW_PORT}" &> /dev/null || break
function start_sauce_connect() {
echo "[ROLLING RESTART] Starting new SC with identifier ${TUNNEL_IDENTIFIER}"
echo "[ROLLING RESTART] on port ${NEW_PORT}"
/Users/sso/Downloads/sc-4.3.14-osx/bin/sc -l sauce_connect.log \
--max-logsize 524288000 \
--se-port ${NEW_PORT} \
--logfile /tmp/sc_log_${TUNNEL_IDENTIFIER}_${NEW_PORT}.log \
--pidfile /tmp/sc_log_${TUNNEL_IDENTIFIER}_${NEW_PORT}.pid \
--tunnel-identifier ${TUNNEL_IDENTIFIER} \
--no-remove-colliding-tunnels \
--wait-tunnel-shutdown &
function stop_sauce_connect() {
echo "[ROLLING RESTART] Attempting stop SC with identifier ${TUNNEL_IDENTIFIER}"
echo "[ROLLING RESTART] skipping new instance running on port ${NEW_PORT}"
| grep -E "sc .*${TUNNEL_IDENTIFIER}" \
| grep -Ev "(${NEW_PORT}|grep)" \
| awk '{ print $2 }' \
| tr '\n' ' ')
if [ "${OLD_SC_PROCESSES}" != "" ]; then
echo "[ROLLING RESTART] Signalling old SC processes: ${OLD_SC_PROCESSES}"
echo "[ROLLING RESTART] Waiting for the new tunnel to start before initiating"
echo "[ROLLING RESTART] graceful shutdown of old tunnels"
sleep 20
wait # come back to the original SC Process
Copy link

And here is a two-pane shell showing a rolling restart happening on the left side, while 3 different batches of tests all run successfully along the way on the right:!

Copy link

lukeis commented Mar 25, 2016

I'm assuming an example usage would be to put in a crontab with calling this script, which would launch a new tunnel, killing the other one after the main one is started (assuming it only takes 20 seconds to start up? might need to adjust that).

There's another scenario that would need to be handled though, when saucelabs kills any open tunnels (which has been happening frequently) we'd want this to auto-start again (why we had a while() { sc } loop)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment