Skip to content

Commit

Permalink
Merge pull request #18 from guzman-raphael/publicdemo
Browse files Browse the repository at this point in the history
Fix auto certificate renewal
  • Loading branch information
mahos authored Apr 1, 2020
2 parents f814a34 + e220683 commit d6a460a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ services:
nginx:
# build: ./nginx
# image: registry.vathes.com/ibl-navigator/nginx:v0.0-dev5
image: registry.vathes.com/ibl-navigator/nginx:v0.0-public3 # for public deploy ?
image: registry.vathes.com/ibl-navigator/nginx:v0.0-public4 # for public deploy ?
environment:
# - URL=datajoint.io # for testdev deploy
# - SUBDOMAINS=testdev # for testdev deploy
Expand Down
22 changes: 15 additions & 7 deletions nginx/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,18 @@ echo "[$(date -u '+%Y-%m-%d %H:%M:%S')][DataJoint]: Enabling SSL feature"
mv /ssl.conf /etc/nginx/conf.d/ssl.conf
update_cert

inotifywait -m /etc/letsencrypt/live/${SUBDOMAINS}.${URL} |
while read path action file; do
if [ "$(echo $action | grep MODIFY)" ] || [ "$(echo $action | grep CREATE)" ] || [ "$(echo $action | grep MOVE)" ]; then
echo "[$(date -u '+%Y-%m-%d %H:%M:%S')][DataJoint]: Renewal: Reloading NGINX since \`$file\` issue \`$action\` event"
update_cert
fi
done
INIT_TIME=$(date +%s)
LAST_MOD_TIME=$(date -r $(echo /etc/letsencrypt/live/${SUBDOMAINS}.${URL}/$(ls -t /etc/letsencrypt/live/${SUBDOMAINS}.${URL}/ | head -n 1)) +%s)
DELTA=$(expr $LAST_MOD_TIME - $INIT_TIME)
while true; do
CURR_FILEPATH=$(ls -t /etc/letsencrypt/live/${SUBDOMAINS}.${URL}/ | head -n 1)
CURR_LAST_MOD_TIME=$(date -r $(echo /etc/letsencrypt/live/${SUBDOMAINS}.${URL}/${CURR_FILEPATH}) +%s)
CURR_DELTA=$(expr $CURR_LAST_MOD_TIME - $INIT_TIME)
if [ "$DELTA" -lt "$CURR_DELTA" ]; then
echo "[$(date -u '+%Y-%m-%d %H:%M:%S')][DataJoint]: Renewal: Reloading NGINX since \`$CURR_FILEPATH\` changed."
update_cert
DELTA=$CURR_DELTA
else
sleep 5
fi
done

0 comments on commit d6a460a

Please sign in to comment.