Skip to content

Commit d561f8d

Browse files
authored
Implement #32
Send already existing certificates to proxy before renewal - after renewal send them again.
1 parent 87e3e2a commit d561f8d

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

renewAndSendToProxy.sh

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,44 @@ TIMEOUT=5
1616

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

19+
# send current certificates to proxy - after that do a certbot renew round (which could take some seconds) and send updated certificates to proxy (faster startup with https when old certificates are still valid)
20+
for d in /etc/letsencrypt/live/*/ ; do
21+
#move to directory
22+
cd $d
23+
24+
#get directory name (which is the name of the regular domain)
25+
folder=${PWD##*/}
26+
27+
#concat certificates
28+
printf "old certificates for $folder will be send to proxy\n"
29+
cat cert.pem chain.pem privkey.pem > $folder.combined.pem
30+
31+
#send to proxy, retry up to 5 times with a timeout of $TIMEOUT seconds
32+
33+
#reset tries to 0
34+
TRIES=0
35+
exitcode=0
36+
until [ $TRIES -ge $MAXRETRIES ]
37+
do
38+
TRIES=$[$TRIES+1]
39+
curl --silent --show-error -i -XPUT \
40+
--data-binary @$folder.combined.pem \
41+
"$PROXY_ADDRESS:8080/v1/docker-flow-proxy/cert?certName=$folder.combined.pem&distribute=true" > /var/log/dockeroutput.log && break
42+
exitcode=$?
43+
if [ $TRIES -eq $MAXRETRIES ]; then
44+
printf "old certificate: ${RED}transmit failed after ${TRIES} attempts.${NC}\n"
45+
else
46+
printf "old certificate: ${RED}transmit failed, we try again in ${TIMEOUT} seconds.${NC}\n"
47+
sleep $TIMEOUT
48+
fi
49+
done
50+
51+
if [ $exitcode -eq 0 ]; then
52+
printf "old certificates: proxy received $folder.combined.pem\n"
53+
fi
54+
done
55+
56+
1957
#full path is needed or it is not started when run as cron
2058

2159
#--no-bootstrap: prevent the certbot-auto script from installing OS-level dependencies

0 commit comments

Comments
 (0)