Skip to content

Instantly share code, notes, and snippets.

@jfurcean
Last active February 10, 2020 03:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jfurcean/0f0b16e81bc9926023a0c98392aa79fa to your computer and use it in GitHub Desktop.
Save jfurcean/0f0b16e81bc9926023a0c98392aa79fa to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# Based off ScottHelme's Lets Encrypt Smart Renew
# https://github.com/ScottHelme/Lets-Encrypt-Smart-Renew
#
# Repalce DOMAIN with the domain of the certificate you are renewing
#
# crontab
# 0 * * * * /path/to/smartRenew.sh
# The remaining life on our certificate below which we should renew (7 days).
RENEW=21
# Set date for backup
TODAY=`date '+%Y_%m_%d'`
# If the certificate has less life remaining than we want.
if ! openssl x509 -checkend $[ 86400 * $RENEW ] -noout -in /etc/lego/certificates/DOMAIN.crt
then
# Then make backup copy of existing cert before starting renew
cp /etc/lego/certificates/DOMAIN.crt /etc/lego/certificates/DOMAIN_$TODAY.crt
# Then call the renewal script.
/etc/lego/renew-certificate.sh
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment