How Does Certbot’s Auto Renew Script Work?

The OpenLiteSpeed WordPress image comes with automatic certificate renewal by default in /etc/cron.d/certbot. An example of the cron job is:

0 */12 * * * root test -x /usr/bin/certbot -a \! -d /run/systemd/system && perl -e 'sleep int(rand(43200))' && certbot -q renew

Once you finish the Let’s Encrypt apply by prompt script, it will auto apply the server hook to the cronjob rule. An example of the cron job is:

0 */12 * * * root test -x /usr/bin/certbot -a \! -d /run/systemd/system && perl -e 'sleep int(rand(43200))' && certbot -q renew --deploy-hook "/usr/local/lsws/bin/lswsctrl restart"

This cron job is triggered twice every day to renew the certificate. The certbot -q renew command will check if the certificate is expiring in the next 30 days. If it is, then certbot will auto renew the certificate quietly without generating output, and auto restart the web server by hook. If the certificate is not expiring, then no action will be performed. When renewing the certificate, the same information provided during certificate creation (such as email address, domain name, web server root path etc.) will be used.

Category: OpenLiteSpeed