Fix retry syntax
This commit is contained in:
		
							parent
							
								
									84842f83a5
								
							
						
					
					
						commit
						9a6b4fd7e4
					
				|  | @ -2,7 +2,7 @@ | ||||||
| 
 | 
 | ||||||
| set -e | set -e | ||||||
| 
 | 
 | ||||||
| # Load common functions | # Load common functions  | ||||||
| source config/tools.sh | source config/tools.sh | ||||||
| 
 | 
 | ||||||
| # Check that required tools are installed | # Check that required tools are installed | ||||||
|  | @ -22,7 +22,7 @@ for i in "$@"; do | ||||||
|       ;; |       ;; | ||||||
|     --debug) |     --debug) | ||||||
|       DEBUG=1 |       DEBUG=1 | ||||||
|       ;; |       ;;   | ||||||
|     *) |     *) | ||||||
|       echo "[$0] ❌ ERROR: unknown parameter \"$i\"" |       echo "[$0] ❌ ERROR: unknown parameter \"$i\"" | ||||||
|       exit 1 |       exit 1 | ||||||
|  | @ -36,7 +36,7 @@ cleanup_on_exit() { | ||||||
| trap cleanup_on_exit EXIT | trap cleanup_on_exit EXIT | ||||||
| 
 | 
 | ||||||
| echo-debug() { | echo-debug() { | ||||||
|   if [[ ${DEBUG} == "1" ]]; then echo "$@"; fi |   if [[ ${DEBUG} == "1" ]]; then echo "$@"; fi  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| ############################################################################################### | ############################################################################################### | ||||||
|  | @ -54,12 +54,12 @@ fi | ||||||
| source .env | source .env | ||||||
| echo "${HTTP_USER}:${HTTP_PASSWORD}" > traefik/http_auth | echo "${HTTP_USER}:${HTTP_PASSWORD}" > traefik/http_auth | ||||||
| 
 | 
 | ||||||
| # Docker-compose settings | # Docker-compose settings   | ||||||
| export COMPOSE_HTTP_TIMEOUT=240 | export COMPOSE_HTTP_TIMEOUT=240 | ||||||
| 
 | 
 | ||||||
| # Retro-compatibility | # Retro-compatibility | ||||||
| [[ -z $HOST_CONFIG_PATH ]] && export HOST_CONFIG_PATH="/data/config" | [[ -z $HOST_CONFIG_PATH ]] && export HOST_CONFIG_PATH="/data/config" | ||||||
| [[ -z $HOST_MEDIA_PATH ]] && export HOST_MEDIA_PATH="/data/torrents" | [[ -z $HOST_MEDIA_PATH ]] && export HOST_MEDIA_PATH="/data/torrents"  | ||||||
| [[ -z $DOWNLOAD_SUBFOLDER ]] && export DOWNLOAD_SUBFOLDER="deluge" | [[ -z $DOWNLOAD_SUBFOLDER ]] && export DOWNLOAD_SUBFOLDER="deluge" | ||||||
| [[ -z $DOCKER_COMPOSE_BINARY ]] && export DOCKER_COMPOSE_BINARY="docker-compose" | [[ -z $DOCKER_COMPOSE_BINARY ]] && export DOCKER_COMPOSE_BINARY="docker-compose" | ||||||
| 
 | 
 | ||||||
|  | @ -68,22 +68,22 @@ if [[ ! -f config.yaml ]]; then | ||||||
|   cp config.sample.yaml config.yaml |   cp config.sample.yaml config.yaml | ||||||
| fi | fi | ||||||
| 
 | 
 | ||||||
| ############################################################################################### | ###############################################################################################   | ||||||
| ###################################### Pre-flight checks ###################################### | ###################################### Pre-flight checks ###################################### | ||||||
| ############################################################################################### | ############################################################################################### | ||||||
| 
 | 
 | ||||||
| echo "[$0] ***** Checking configuration... *****" | echo "[$0] ***** Checking configuration... *****" | ||||||
| 
 | 
 | ||||||
| retry $max_retries yq eval -o json config.yaml > config.json | retry --max-retries $max_retries -- yq eval -o json config.yaml > config.json | ||||||
| 
 | 
 | ||||||
| if [[ ${CHECK_FOR_OUTDATED_CONFIG} == true ]]; then | if [[ ${CHECK_FOR_OUTDATED_CONFIG} == true ]]; then | ||||||
|   nb_services=$(cat config.json | jq '.services | length') |   nb_services=$(cat config.json | jq '.services | length') | ||||||
|   nb_services_sample=$(yq eval -o json config.sample.yaml | jq '.services | length') |   nb_services_sample=$(yq eval -o json config.sample.yaml | jq '.services | length') | ||||||
|   if [[ $nb_services_sample -gt $nb_services ]]; then |   if [[ $nb_services_sample -gt $nb_services ]]; then | ||||||
|     echo "[$0] There are more services in the config.sample.yaml than in your config.yaml" |     echo "[$0] There are more services in the config.sample.yaml than in your config.yaml"  | ||||||
|     echo "[$0] You should check config.sample.yaml because it seems there are new services available for you:" |     echo "[$0] You should check config.sample.yaml because it seems there are new services available for you:" | ||||||
|     diff -u config.yaml config.sample.yaml | grep "name:" | grep -E "^\+" || true |     diff -u config.yaml config.sample.yaml | grep "name:" | grep -E "^\+" || true | ||||||
|   fi |   fi     | ||||||
| fi | fi | ||||||
| 
 | 
 | ||||||
| # Check if some services have vpn enabled, that gluetun itself is enabled | # Check if some services have vpn enabled, that gluetun itself is enabled | ||||||
|  | @ -92,31 +92,32 @@ gluetun_enabled=$(cat config.json | jq '[.services[] | select(.name=="gluetun" a | ||||||
| if [[ ${nb_vpn} -gt 0 && ${gluetun_enabled} == 0 ]]; then | if [[ ${nb_vpn} -gt 0 && ${gluetun_enabled} == 0 ]]; then | ||||||
|   echo "[$0] ERROR. ${nb_vpn} VPN-enabled services have been enabled BUT gluetun has not been enabled. Please check your config.yaml file." |   echo "[$0] ERROR. ${nb_vpn} VPN-enabled services have been enabled BUT gluetun has not been enabled. Please check your config.yaml file." | ||||||
|   echo "[$0] ******* Exiting *******" |   echo "[$0] ******* Exiting *******" | ||||||
|   exit 1 |   exit 1   | ||||||
| fi | fi | ||||||
| 
 | 
 | ||||||
| # Determine what host Flood should connect to | # Determine what host Flood should connect to  | ||||||
| # => If deluge vpn is enabled => gluetun | # => If deluge vpn is enabled => gluetun | ||||||
| # => If deluge vpn is disabled => deluge | # => If deluge vpn is disabled => deluge | ||||||
| if [[ $(cat config.json | jq '[.services[] | select(.name=="flood" and .enabled==true)] | length') -eq 1 ]]; then | if [[ $(cat config.json | jq '[.services[] | select(.name=="flood" and .enabled==true)] | length') -eq 1 ]]; then | ||||||
|   # Check that if flood is enabled, deluge should also be enabled |   # Check that if flood is enabled, deluge should also be enabled | ||||||
|   if [[ $(cat config.json | jq '[.services[] | select(.name=="deluge" and .enabled==false)] | length') -eq 1 ]]; then |   if [[ $(cat config.json | jq '[.services[] | select(.name=="deluge" and .enabled==false)] | length') -eq 1 ]]; then | ||||||
|     echo "[$0] ERROR. Flood is enabled but Deluge is not. Please either enable Deluge or disable Flood as Flood depends on Deluge." |     echo "[$0] ERROR. Flood is enabled but Deluge is not. Please either enable Deluge or disable Flood as Flood depends on Deluge."  | ||||||
|     echo "[$0] ******* Exiting *******" |     echo "[$0] ******* Exiting *******" | ||||||
|     exit 1 |     exit 1 | ||||||
|   fi |   fi | ||||||
|  |    | ||||||
|   # Determine deluge hostname (for flood) based on the VPN status (enabled or not) of deluge |   # Determine deluge hostname (for flood) based on the VPN status (enabled or not) of deluge | ||||||
|   if [[ $(cat config.json | jq '[.services[] | select(.name=="deluge" and .enabled==true and .vpn==true)] | length') -eq 1 ]]; then |   if [[ $(cat config.json | jq '[.services[] | select(.name=="deluge" and .enabled==true and .vpn==true)] | length') -eq 1 ]]; then   | ||||||
|     export DELUGE_HOST="gluetun" |     export DELUGE_HOST="gluetun" | ||||||
|   elif [[ $(cat config.json | jq '[.services[] | select(.name=="deluge" and .enabled==true and .vpn==false)] | length') -eq 1 ]]; then |   elif [[ $(cat config.json | jq '[.services[] | select(.name=="deluge" and .enabled==true and .vpn==false)] | length') -eq 1 ]]; then | ||||||
|     export DELUGE_HOST="deluge" |     export DELUGE_HOST="deluge" | ||||||
|   fi |   fi | ||||||
| 
 | 
 | ||||||
|   # Specific instructions for Flood |   # Specific instructions for Flood   | ||||||
|   # User for Deluge daemon RPC has to be created in deluge auth config file |   # User for Deluge daemon RPC has to be created in deluge auth config file | ||||||
|   if [[ ! -z ${FLOOD_PASSWORD} && ${FLOOD_AUTOCREATE_USER_IN_DELUGE_DAEMON} == true ]]; then |   if [[ ! -z ${FLOOD_PASSWORD} && ${FLOOD_AUTOCREATE_USER_IN_DELUGE_DAEMON} == true ]]; then | ||||||
|     if ! grep -q "flood" $HOST_CONFIG_PATH/deluge/auth; then |     if ! grep -q "flood" $HOST_CONFIG_PATH/deluge/auth; then | ||||||
|       echo "flood:${FLOOD_PASSWORD}:10" >> $HOST_CONFIG_PATH/deluge/auth |       echo "flood:${FLOOD_PASSWORD}:10" >> $HOST_CONFIG_PATH/deluge/auth  | ||||||
|     else |     else | ||||||
|       echo "[$0] No need to add user/password for flood as it has already been created." |       echo "[$0] No need to add user/password for flood as it has already been created." | ||||||
|       echo "[$0] Consider setting FLOOD_AUTOCREATE_USER_IN_DELUGE_DAEMON variable to false in .env file." |       echo "[$0] Consider setting FLOOD_AUTOCREATE_USER_IN_DELUGE_DAEMON variable to false in .env file." | ||||||
|  | @ -124,11 +125,11 @@ if [[ $(cat config.json | jq '[.services[] | select(.name=="flood" and .enabled= | ||||||
|   fi |   fi | ||||||
| fi | fi | ||||||
| 
 | 
 | ||||||
| # Check that if calibre-web is enabled, calibre should also be enabled | # Check that if calibre-web is enabled, calibre should also be enabled   | ||||||
| if [[ $(cat config.json | jq '[.services[] | select(.name=="calibre-web" and .enabled==true)] | length') -eq 1 ]]; then | if [[ $(cat config.json | jq '[.services[] | select(.name=="calibre-web" and .enabled==true)] | length') -eq 1 ]]; then | ||||||
|   if [[ $(cat config.json | jq '[.services[] | select(.name=="calibre" and .enabled==false)] | length') -eq 1 ]]; then |   if [[ $(cat config.json | jq '[.services[] | select(.name=="calibre" and .enabled==false)] | length') -eq 1 ]]; then | ||||||
|     echo "[$0] ERROR. Calibre-web is enabled but Calibre is not. Please either enable Calibre or disable Calibre-web as Calibre-web depends on Calibre." |     echo "[$0] ERROR. Calibre-web is enabled but Calibre is not. Please either enable Calibre or disable Calibre-web as Calibre-web depends on Calibre." | ||||||
|     echo "[$0] ******* Exiting *******" |     echo "[$0] ******* Exiting *******"  | ||||||
|     exit 1 |     exit 1 | ||||||
|   fi |   fi | ||||||
| fi | fi | ||||||
|  | @ -137,23 +138,23 @@ fi | ||||||
| rm -f $f traefik/custom/custom-* | rm -f $f traefik/custom/custom-* | ||||||
| for f in `find samples/custom-traefik -maxdepth 1 -mindepth 1 -type f | grep -E "\.yml$|\.yaml$" | sort`; do | for f in `find samples/custom-traefik -maxdepth 1 -mindepth 1 -type f | grep -E "\.yml$|\.yaml$" | sort`; do | ||||||
|   echo "[$0] Applying custom Traefik config $f..." |   echo "[$0] Applying custom Traefik config $f..." | ||||||
|   cp $f traefik/custom/custom-$(basename $f) |   cp $f traefik/custom/custom-$(basename $f)   | ||||||
| done | done | ||||||
| 
 | 
 | ||||||
| # Detect Synology devices for Netdata compatibility | # Detect Synology devices for Netdata compatibility | ||||||
| if [[ $(cat config.json | jq '[.services[] | select(.name=="netdata" and .enabled==true)] | length') -eq 1 ]]; then | if [[ $(cat config.json | jq '[.services[] | select(.name=="netdata" and .enabled==true)] | length') -eq 1 ]]; then | ||||||
|   if [[ $(uname -a | { grep synology || true; } | wc -l) -eq 1 ]]; then |   if [[ $(uname -a | { grep synology || true; } | wc -l) -eq 1 ]]; then     | ||||||
|     export OS_RELEASE_FILEPATH="/etc/VERSION" |     export OS_RELEASE_FILEPATH="/etc/VERSION" | ||||||
|   else |   else   | ||||||
|     export OS_RELEASE_FILEPATH="/etc/os-release" |     export OS_RELEASE_FILEPATH="/etc/os-release" | ||||||
|   fi |   fi | ||||||
| fi | fi | ||||||
| 
 | 
 | ||||||
| ############################################################################################### | ############################################################################################### | ||||||
| ####################################### SERVICES PARSING ###################################### | ####################################### SERVICES PARSING ######################################   | ||||||
| ############################################################################################### | ############################################################################################### | ||||||
| 
 | 
 | ||||||
| echo "[$0] ***** Generating configuration... *****"  | echo "[$0] ***** Generating configuration... *****" | ||||||
| 
 | 
 | ||||||
| # Cleanup files before start, in case there was a change we start from scratch at every script execution | # Cleanup files before start, in case there was a change we start from scratch at every script execution | ||||||
| rm -f services/generated/*-vpn.yaml | rm -f services/generated/*-vpn.yaml | ||||||
|  | @ -166,15 +167,15 @@ for json in $(yq eval -o json config.yaml | jq -c ".services[]"); do | ||||||
|   enabled=$(echo $json | jq -r .enabled) |   enabled=$(echo $json | jq -r .enabled) | ||||||
|   vpn=$(echo $json | jq -r .vpn) |   vpn=$(echo $json | jq -r .vpn) | ||||||
| 
 | 
 | ||||||
|   # Skip disabled services |   # Skip disabled services   | ||||||
|   if [[ ${enabled} == "false" ]]; then |   if [[ ${enabled} == "false" ]]; then | ||||||
|     echo-debug "[$0] Service $name is disabled. Skipping it." |     echo-debug "[$0] Service $name is disabled. Skipping it." | ||||||
|     continue |     continue | ||||||
|   fi |   fi | ||||||
| 
 | 
 | ||||||
|   echo-debug "[$0] ➡️  Parsing service: \"$name\"..." |   echo-debug "[$0] ➡️  Parsing service: \"$name\"..." | ||||||
| 
 |    | ||||||
|   # Default docker-compose filename is the service name + .yaml.  |   # Default docker-compose filename is the service name + .yaml. | ||||||
|   # Take into account explicit filename if specified in config |   # Take into account explicit filename if specified in config | ||||||
|   customFile=$(echo $json | jq -r .customFile) |   customFile=$(echo $json | jq -r .customFile) | ||||||
|   file="$name.yaml" |   file="$name.yaml" | ||||||
|  | @ -186,7 +187,7 @@ for json in $(yq eval -o json config.yaml | jq -c ".services[]"); do | ||||||
|   # Append $file to global list of files which will be passed to docker commands |   # Append $file to global list of files which will be passed to docker commands | ||||||
|   ALL_SERVICES="${ALL_SERVICES} -f services/${file}" |   ALL_SERVICES="${ALL_SERVICES} -f services/${file}" | ||||||
| 
 | 
 | ||||||
|   # For services with VPN enabled, add a docker-compose "override" file specifying that the service network should |   # For services with VPN enabled, add a docker-compose "override" file specifying that the service network should  | ||||||
|   # go through gluetun (main vpn client service). |   # go through gluetun (main vpn client service). | ||||||
|   if [[ ${vpn} == "true" ]]; then |   if [[ ${vpn} == "true" ]]; then | ||||||
|     echo "services.${name}.network_mode: service:gluetun" > ${name}-vpn.props |     echo "services.${name}.network_mode: service:gluetun" > ${name}-vpn.props | ||||||
|  | @ -211,13 +212,13 @@ for json in $(yq eval -o json config.yaml | jq -c ".services[]"); do | ||||||
|   for rule in $(echo $json | jq -c .traefik.rules[]); do |   for rule in $(echo $json | jq -c .traefik.rules[]); do | ||||||
|     ((i=i+1)) |     ((i=i+1)) | ||||||
|     host=$(echo $rule | jq -r .host) |     host=$(echo $rule | jq -r .host) | ||||||
|     internalPort=$(echo $rule | jq -r .internalPort) |     internalPort=$(echo $rule | jq -r .internalPort)   | ||||||
|     httpAuth=$(echo $rule | jq -r .httpAuth) |     httpAuth=$(echo $rule | jq -r .httpAuth) | ||||||
|     echo-debug "[$0]      Host => ${host}" |     echo-debug "[$0]      Host => ${host}" | ||||||
|     echo-debug "[$0]      Internal Port => ${internalPort}" |     echo-debug "[$0]      Internal Port => ${internalPort}" | ||||||
|     echo-debug "[$0]      Http Authentication => ${httpAuth}" |     echo-debug "[$0]      Http Authentication => ${httpAuth}" | ||||||
| 
 | 
 | ||||||
|     # If VPN => Traefik rule should redirect to gluetun container |     # If VPN => Traefik rule should redirect to gluetun container  | ||||||
|     backendHost=${name} |     backendHost=${name} | ||||||
|     [[ ${vpn} == "true" ]] && backendHost="gluetun" |     [[ ${vpn} == "true" ]] && backendHost="gluetun" | ||||||
| 
 | 
 | ||||||
|  | @ -235,7 +236,7 @@ for json in $(yq eval -o json config.yaml | jq -c ".services[]"); do | ||||||
|     middlewareCount=0 |     middlewareCount=0 | ||||||
|     if [[ ${httpAuth} == "true" ]]; then |     if [[ ${httpAuth} == "true" ]]; then | ||||||
|       echo "http.routers.${ruleId}.middlewares.${middlewareCount}: common-auth@file" >> rules.props |       echo "http.routers.${ruleId}.middlewares.${middlewareCount}: common-auth@file" >> rules.props | ||||||
|       ((middlewareCount=middlewareCount+1)) |       ((middlewareCount=middlewareCount+1))  | ||||||
|     fi |     fi | ||||||
| 
 | 
 | ||||||
|     traefikService=$(echo $rule | jq -r .service) |     traefikService=$(echo $rule | jq -r .service) | ||||||
|  | @ -246,7 +247,7 @@ for json in $(yq eval -o json config.yaml | jq -c ".services[]"); do | ||||||
|     fi |     fi | ||||||
| 
 | 
 | ||||||
|     # Check if httpOnly flag is enabled |     # Check if httpOnly flag is enabled | ||||||
|     # If enabled => Specify to use only "insecure" (port 80) entrypoint |     # If enabled => Specify to use only "insecure" (port 80) entrypoint   | ||||||
|     # If not => use all entryPoints (by not specifying any) but force redirection to https |     # If not => use all entryPoints (by not specifying any) but force redirection to https | ||||||
|     httpOnly=$(echo $rule | jq -r .httpOnly) |     httpOnly=$(echo $rule | jq -r .httpOnly) | ||||||
|     if [[ ${httpOnly} == true ]]; then |     if [[ ${httpOnly} == true ]]; then | ||||||
|  | @ -257,11 +258,11 @@ for json in $(yq eval -o json config.yaml | jq -c ".services[]"); do | ||||||
|     fi |     fi | ||||||
| 
 | 
 | ||||||
|     # If the specified service does not contain a "@" => we create it |     # If the specified service does not contain a "@" => we create it | ||||||
|     # If the service has a @, it means it is defined elsewhere so we do not create it (custom file, @internal...) |     # If the service has a @, it means it is defined elsewhere so we do not create it (custom file, @internal...)   | ||||||
|     if echo ${traefikService} | grep -vq "@"; then |     if echo ${traefikService} | grep -vq "@"; then | ||||||
|       echo "http.services.${ruleId}.loadBalancer.servers.0.url: ${internalScheme}://${backendHost}:${internalPort}" >> rules.props |       echo "http.services.${ruleId}.loadBalancer.servers.0.url: ${internalScheme}://${backendHost}:${internalPort}" >> rules.props | ||||||
|     fi |     fi | ||||||
|      | 
 | ||||||
|   done |   done | ||||||
| done | done | ||||||
| 
 | 
 | ||||||
|  | @ -272,7 +273,7 @@ rm -f rules.props | ||||||
| 
 | 
 | ||||||
| # Post-transformations on the rules file | # Post-transformations on the rules file | ||||||
| # sed -i "s/EMPTYMAP/{}/g" traefik/custom/dynamic-rules.yaml | # sed -i "s/EMPTYMAP/{}/g" traefik/custom/dynamic-rules.yaml | ||||||
| # Add simple quotes around Host rule   | # Add simple quotes around Host rule  | ||||||
| sed -i --regexp-extended "s/^(.*: )(Host.*$)/\1'\2'/g" traefik/custom/dynamic-rules.yaml | sed -i --regexp-extended "s/^(.*: )(Host.*$)/\1'\2'/g" traefik/custom/dynamic-rules.yaml | ||||||
| # Add double quotes around the backend traefik service | # Add double quotes around the backend traefik service | ||||||
| sed -i --regexp-extended "s/^(.*url: )(.*$)/\1\"\2\"/g" traefik/custom/dynamic-rules.yaml | sed -i --regexp-extended "s/^(.*url: )(.*$)/\1\"\2\"/g" traefik/custom/dynamic-rules.yaml | ||||||
|  | @ -286,19 +287,19 @@ echo "[$0] ***** Config OK. Launching services... *****" | ||||||
| if [[ "${SKIP_PULL}" != "1" ]]; then | if [[ "${SKIP_PULL}" != "1" ]]; then | ||||||
|   echo "[$0] ***** Pulling all images... *****" |   echo "[$0] ***** Pulling all images... *****" | ||||||
|    |    | ||||||
|   retry $max_retries ${DOCKER_COMPOSE_BINARY} ${ALL_SERVICES} pull |   retry --max-retries $max_retries -- ${DOCKER_COMPOSE_BINARY} ${ALL_SERVICES} pull | ||||||
| fi | fi | ||||||
| 
 | 
 | ||||||
| echo "[$0] ***** Recreating containers if required... *****" | echo "[$0] ***** Recreating containers if required... *****" | ||||||
| 
 | 
 | ||||||
| retry $max_retries ${DOCKER_COMPOSE_BINARY} ${ALL_SERVICES} up -d --remove-orphans | retry --max-retries $max_retries -- ${DOCKER_COMPOSE_BINARY} ${ALL_SERVICES} up -d --remove-orphans | ||||||
| 
 | 
 | ||||||
| echo "[$0] ***** Done updating containers *****" | echo "[$0] ***** Done updating containers *****"  | ||||||
| 
 | 
 | ||||||
| echo "[$0] ***** Clean unused images and volumes... *****" | echo "[$0] ***** Clean unused images and volumes... *****" | ||||||
| 
 | 
 | ||||||
| retry $max_retries docker image prune -af | retry --max-retries $max_retries -- docker image prune -af | ||||||
| retry $max_retries docker volume prune -f | retry --max-retries $max_retries -- docker volume prune -f | ||||||
| 
 | 
 | ||||||
| echo "[$0] ***** Done! *****" | echo "[$0] ***** Done! *****" | ||||||
| exit 0 | exit 0 | ||||||
		Loading…
	
		Reference in New Issue