Skip to content

Instantly share code, notes, and snippets.

@jabis
Last active December 3, 2015 23:22
Show Gist options
  • Save jabis/1d33d131ae1901824ce0 to your computer and use it in GitHub Desktop.
Save jabis/1d33d131ae1901824ce0 to your computer and use it in GitHub Desktop.
Letsencrypt auto-renewal crontab script by majuscule
#!/usr/bin/env bash
# Auto renewal script for letsencrypt
# https://disinclined.org/share/renew-ssl-certificates.sh.txt
# this script is for singular domain-named files in /etc/nginx/sites-enabled, so check paths to match and enjoy
# Created by majuscule @ #letsencrypt on freenode ( dylan@disinclined.org )
ERROR=0
for DOMAIN in $(ls -1 /etc/nginx/sites-enabled); do
/root/letsencrypt/letsencrypt-auto certonly \
--server 'https://acme-v01.api.letsencrypt.org/directory' \
-d $DOMAIN -d www.$DOMAIN \
--webroot -w /srv/http/$DOMAIN \
--rsa-key-size 4096 \
--renew-by-default
EXIT_CODE=$?
if [[ $EXIT_CODE -ne 0 ]]; then
ERROR=1;
cat <<-END | mail -s 'Certificate Renewal Failure' dylan@disinclined.org
letsencrypt-auto failed to renew cert for $DOMAIN.
exit code was [ $EXIT_CODE ].
END
fi
done
if [[ $ERROR -eq 0 ]]; then
systemctl reload nginx postfix
systemctl restart dovecot
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment