Skip to content

Instantly share code, notes, and snippets.

@urbanslug
Last active April 24, 2016 19:38
Show Gist options
  • Save urbanslug/bfa654e8420a0a63f5f15dbdb3d28dff to your computer and use it in GitHub Desktop.
Save urbanslug/bfa654e8420a0a63f5f15dbdb3d28dff to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# cron job to update letsencrypt cert from hyper_ch #letsencrypt irc.freenode.net
days=60 # After how many days should the cert be renewed?
domain="blog.urbanslug.com" # Provide domain name
#*************************************************************************************************************#
# #
# HERE BE DRAGONS #
# #
#*************************************************************************************************************#
fileTime=$(stat -c %Y "/etc/letsencrypt/live/${domain}/fullchain.pem")
curTime=$(date +%s)
diff=$(( (curTime - fileTime) / 86400 ))
if [[ ${diff} -ge ${days} ]]; then
# Original Script
cd /opt/letsencrypt/
./letsencrypt-auto --config /etc/letsencrypt/configs/${domain}.conf certonly
if [[ $? -ne 0 ]]; then
ERRORLOG=$(tail /var/log/letsencrypt/letsencrypt.log)
echo -e "The Let's Encrypt cert has not been renewed! \n \n" \
$ERRORLOG
else
nginx -s reload
fi
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment