Skip to content

Commit

Permalink
Add retry option to curl when uploading certificates (#17)
Browse files Browse the repository at this point in the history
* Update renewAndSendToProxy.sh

Add a retry option in case curl fails

* Update renewAndSendToProxy.sh

* Update renewAndSendToProxy.sh

Fix updating the wrong variable

* Update renewAndSendToProxy.sh

Move counter update to the end of the loop, so our counter logic is
valid

* Update renewAndSendToProxy.sh

Add options to curl to hide the progress bar but show errors which can
be helpful

* Update renewAndSendToProxy.sh

Move counter back to the beginning as this avoids any logic in the print
statement

* Update renewAndSendToProxy.sh

Move sleep statement to avoid unnecessary sleep
  • Loading branch information
jorianvo authored and hamburml committed Mar 27, 2017
1 parent c039523 commit 881320f
Showing 1 changed file with 29 additions and 5 deletions.
34 changes: 29 additions & 5 deletions renewAndSendToProxy.sh
Expand Up @@ -5,6 +5,15 @@ RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m' # No Color

#times we tried curl
TRIES=0

#maximum number of retries
MAXRETRIES=5

#timeout
TIMEOUT=5

printf "${GREEN}Hello! renewAndSendToProxy runs. Today is $(date)${NC}\n"

#full path is needed or it is not started when run as cron
Expand All @@ -25,14 +34,29 @@ for d in /etc/letsencrypt/live/*/ ; do
cat cert.pem chain.pem privkey.pem > $folder.combined.pem
printf "${GREEN}generated $folder.combined.pem${NC}\n"

#send to proxy
#send to proxy, retry up to 5 times with a timeout of $TIMEOUT seconds
printf "${GREEN}transmit $folder.combined.pem to $PROXY_ADDRESS${NC}\n"

curl -i -XPUT \
--data-binary @$folder.combined.pem \
"$PROXY_ADDRESS:8080/v1/docker-flow-proxy/cert?certName=$folder.combined.pem&distribute=true" > /var/log/dockeroutput.log
exitcode=0
until [ $TRIES -ge $MAXRETRIES ]
do
TRIES=$[$TRIES+1]
curl --silent --show-error -i -XPUT \
--data-binary @$folder.combined.pem \
"$PROXY_ADDRESS:8080/v1/docker-flow-proxy/cert?certName=$folder.combined.pem&distribute=true" > /var/log/dockeroutput.log && break
exitcode=$?

if [ $TRIES -eq $MAXRETRIES ]; then
printf "${RED}transmit failed after ${TRIES} attempts.${NC}\n"
else
printf "${RED}transmit failed, we try again in ${TIMEOUT} seconds.${NC}\n"
sleep $TIMEOUT
fi
done

printf "proxy received $folder.combined.pem\n"
if [ $exitcode -eq 0 ]; then
printf "proxy received $folder.combined.pem\n"
fi

done

Expand Down

0 comments on commit 881320f

Please sign in to comment.