allomov
6/10/2016 - 6:48 PM

wait-for-bosh-lock.sh

wait_lock() {
  local deployment="$1"; shift
  local timeout=$(($(date +%s) + ${1:-120})) # by default timeout is 120 secs
  local iteration=0

  bosh locks &>/dev/null | grep $deployment

  while ([ $? == 1 ] && [ $(date +%s) -lt $timeout ]) ; do
    sleep 10
    ((iteration++))
    echo "Waiting for a lock on $deployment deployment for $(echo $iteration)0 seconds"
    bosh locks &>/dev/null | grep $deployment
  done

  bosh locks &>/dev/null | grep $deployment
  if [ $? == 1 ] ; then
    echo "Timeout error: can't wait lock for $deployment deployment (timeout is ${1:-120} seconds)"
  fi
}