Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save wuftymerguftyguff/fb0162f5740a5d25b3d63a1de1872547 to your computer and use it in GitHub Desktop.
Save wuftymerguftyguff/fb0162f5740a5d25b3d63a1de1872547 to your computer and use it in GitHub Desktop.
renew lets encrypt certs automatically when olde than 60 days for nginx
#!/bin/sh
# create new certs
cd /opt/letsencrypt
RESTART=false
for conf in $(ls -1 /etc/letsencrypt/live/); do
UPDATE=false
for file in $(find -L /etc/letsencrypt/live/$conf -type f -not -newermt '-60 days' );do
UPDATE=true
done
if [ "$UPDATE" = true ]
then
RESTART=true
./letsencrypt-auto --force-renewal --config "/etc/letsencrypt/configs/${conf}.conf" certonly
fi
done
# make sure nginx picks them up if its config is valid
if [ "$RESTART" = true ]
then
nginx -t && sudo nginx -s reload
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment