Last active
December 3, 2015 23:22
-
-
Save jabis/1d33d131ae1901824ce0 to your computer and use it in GitHub Desktop.
Letsencrypt auto-renewal crontab script by majuscule
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 ( [email protected] ) | |
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' [email protected] | |
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