How to automatically renew certificates?

To be honest, I call the below script in crontab.

# Renew Let's Encrypt SSL cert
                                                                                                                                               

                                                                                                                                               
cd /opt/letsencrypt/
./letsencrypt-auto --config /etc/letsencrypt/cli.ini -d yourdomain.com -d www.yourdomain.com certonly
                                                                                                                                               
if [ $? -ne 0 ]
 then
        ERRORLOG=`tail /var/log/letsencrypt/letsencrypt.log`
        echo -e "The Lets Encrypt Cert has not been renewed! \n \n" $ERRORLOG | mail -s "Lets Encrypt Cert Alert" postmaster@yourdomain.com
 else
        service apache2 reload
fi
                                                                                                                                               
exit 0
3 Likes