Instead of sleep, wait until sauceconnect tunnel is up.

This commit is contained in:
Klaus Schniedergers 2014-03-07 13:41:56 -08:00
parent 74aa1fe9ac
commit 4cf331a5be
1 changed files with 21 additions and 7 deletions

View File

@ -29,8 +29,9 @@ DAEMON=""
# You must configure there your API KEY too
[ -r /etc/default/$NAME ] && . /etc/default/$NAME
READY_FILE=$LOG_DIR/ready_$$
DAEMON="$SAUCE_CONNECT"
DAEMON_ARGS="--logfile $LOG_FILE -u $API_USER -k $API_KEY"
DAEMON_ARGS="--logfile $LOG_FILE --readyfile $READY_FILE -u $API_USER -k $API_KEY"
# Exit if the package is not installed
[ -x "$DAEMON" ] || exit 0
@ -52,18 +53,31 @@ do_start()
# 0 if daemon has been started
# 1 if daemon was already running
# 2 if daemon could not be started
#start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
# || return 1
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
|| return 1
# readyfile is being created by sc when the tunnel is ready
[ -f "${READY_FILE}" ] && rm -f ${READY_FILE}
CUSER=""
[ -n "$USERNAME" ] && [ -n "$GROUP"] && CUSER="-c $USERNAME:$GROUP"
start-stop-daemon -b -m --chdir $LOG_DIR $CUSER --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
$DAEMON_ARGS \
|| return 2
sleep 10
# Add code here, if necessary, that waits for the process to be ready
# to handle requests from services started subsequently which depend
# on this one. As a last resort, sleep for some time.
# Wait for the tunnel to be ready, but time out with error after MAX_WAIT seconds
MAX_WAIT=180
WAIT_INTERVAL=3
MAX_TRIES=$((MAX_WAIT / WAIT_INTERVAL))
echo -n "Waiting for tunnel"
TRIES=$MAX_TRIES
while [ ! -f "${READY_FILE}" ]; do
sleep $WAIT_INTERVAL
TRIES=$((TRIES - 1))
[ $TRIES -gt 0 ] || return 2
echo -n "."
done
echo " ready."
}
#