Merge pull request #44 from samply/feature/retry-git
Retry git fetch/pull to make it more resilient to e.g. network outages
This commit is contained in:
		@@ -136,6 +136,28 @@ setHostname() {
 | 
				
			|||||||
	fi
 | 
						fi
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# from: https://gist.github.com/sj26/88e1c6584397bb7c13bd11108a579746
 | 
				
			||||||
 | 
					# ex. use: retry 5 /bin/false
 | 
				
			||||||
 | 
					function retry {
 | 
				
			||||||
 | 
					  local retries=$1
 | 
				
			||||||
 | 
					  shift
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  local count=0
 | 
				
			||||||
 | 
					  until "$@"; do
 | 
				
			||||||
 | 
					    exit=$?
 | 
				
			||||||
 | 
					    wait=$((2 ** $count))
 | 
				
			||||||
 | 
					    count=$(($count + 1))
 | 
				
			||||||
 | 
					    if [ $count -lt $retries ]; then
 | 
				
			||||||
 | 
					      echo "Retry $count/$retries exited with code $exit, retrying in $wait seconds..."
 | 
				
			||||||
 | 
					      sleep $wait
 | 
				
			||||||
 | 
					    else
 | 
				
			||||||
 | 
					      echo "Retry $count/$retries exited with code $exit, giving up."
 | 
				
			||||||
 | 
					      return $exit
 | 
				
			||||||
 | 
					    fi
 | 
				
			||||||
 | 
					  done
 | 
				
			||||||
 | 
					  return 0
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
##Setting Network properties
 | 
					##Setting Network properties
 | 
				
			||||||
# currently not needed
 | 
					# currently not needed
 | 
				
			||||||
#export HOSTIP=$(MSYS_NO_PATHCONV=1 docker run --rm --add-host=host.docker.internal:host-gateway ubuntu cat /etc/hosts | grep 'host.docker.internal' | awk '{print $1}');
 | 
					#export HOSTIP=$(MSYS_NO_PATHCONV=1 docker run --rm --add-host=host.docker.internal:host-gateway ubuntu cat /etc/hosts | grep 'host.docker.internal' | awk '{print $1}');
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -48,10 +48,10 @@ for DIR in /etc/bridgehead $(pwd); do
 | 
				
			|||||||
  old_git_hash="$(git -C $DIR rev-parse --verify HEAD)"
 | 
					  old_git_hash="$(git -C $DIR rev-parse --verify HEAD)"
 | 
				
			||||||
  if [ -z "$HTTP_PROXY_URL" ]; then
 | 
					  if [ -z "$HTTP_PROXY_URL" ]; then
 | 
				
			||||||
    log "INFO" "Git is using no proxy!"
 | 
					    log "INFO" "Git is using no proxy!"
 | 
				
			||||||
    OUT=$(git -C $DIR fetch 2>&1 && git -C $DIR pull 2>&1)
 | 
					    OUT=$(retry 5 git -C $DIR fetch 2>&1 && retry 5 git -C $DIR pull 2>&1)
 | 
				
			||||||
  else
 | 
					  else
 | 
				
			||||||
    log "INFO" "Git is using proxy ${HTTP_PROXY_URL} from ${CONFFILE}"
 | 
					    log "INFO" "Git is using proxy ${HTTP_PROXY_URL} from ${CONFFILE}"
 | 
				
			||||||
    OUT=$(git -c http.proxy=$HTTP_PROXY_URL -c https.proxy=$HTTPS_PROXY_URL -C $DIR fetch 2>&1 && git -c http.proxy=$HTTP_PROXY_URL -c https.proxy=$HTTPS_PROXY_URL -C $DIR pull 2>&1)
 | 
					    OUT=$(retry 5 git -c http.proxy=$HTTP_PROXY_URL -c https.proxy=$HTTPS_PROXY_URL -C $DIR fetch 2>&1 && retry 5 git -c http.proxy=$HTTP_PROXY_URL -c https.proxy=$HTTPS_PROXY_URL -C $DIR pull 2>&1)
 | 
				
			||||||
  fi
 | 
					  fi
 | 
				
			||||||
  if [ $? -ne 0 ]; then
 | 
					  if [ $? -ne 0 ]; then
 | 
				
			||||||
    report_error log "Unable to update git $DIR: $OUT"
 | 
					    report_error log "Unable to update git $DIR: $OUT"
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user