DEV Community

sunah kim
sunah kim

Posted on Originally published at zenn.dev

Having 'certbot renew' in cron is not the same as auto-renewal

What happened

While doing an inventory of a production site, I was asked: "Is SSL certificate auto-renewal set up?" I checked the server's crontab, and there it was:

0 1 1 * * certbot renew
Enter fullscreen mode Exit fullscreen mode

I almost answered "yes, it's set up" — and then stopped. This runs once a month (1 AM on the 1st). And there was no hook anywhere to reload the web server after renewal.

Apache loads certificates into memory at startup, so even if the file on disk is replaced, it keeps serving the old certificate until you reload. In other words, this cron job "might replace the certificate file, but the site will never pick it up." And yet this server had gone years without a certificate expiry. Suddenly I was in the odd position of not being able to explain why it had been working.

Root cause — a one-shot monthly check, and an accidental reload

Three things came out of digging in.

① Monthly means effectively one attempt. Let's Encrypt certificates are valid for 90 days, and certbot starts attempting renewal 30 days before expiry. With a monthly cron, only one run lands inside that 30-day window. For a certificate expiring on Dec 30: if the Dec 1 run fails, the next attempt is Jan 1 — after expiry. One transient network issue or a hiccup on Let's Encrypt's side at the wrong moment, and the site goes down.

② Apache does not re-read certificates on its own. mod_ssl reads certificates only at start/reload. A successful certbot renew without a reload means browsers keep getting the old certificate.

③ What had been saving us was logrotate. So why had nothing broken? journalctl answered that:

$ journalctl -u httpd | grep Reloaded
Nov 21 03:12:01 ip-xxx systemd[1]: Reloaded The Apache HTTP Server.
(one line every Saturday)
Enter fullscreen mode Exit fullscreen mode

The httpd logrotate config ran systemctl reload httpd every Saturday night to rotate logs, so a renewed certificate was accidentally picked up within a week. Auto-renewal wasn't actually working — we were free-riding on a weekly reload that existed for a completely different purpose.

One more confusing detail worth noting: ssl.conf referenced an expired self-signed certificate called localhost.crt, which gave me a brief scare. It turned out to be the OS-bundled default dummy, unrelated to the site's actual vhost. It's a classic red herring during this kind of investigation.

The fix — a 3-line daily check with a reload hook

Fortunately, the dev server already had the correct shape: a 3-line script in /etc/cron.daily/.

#!/bin/sh
# /etc/cron.daily/certbot-renew
certbot renew --quiet
systemctl reload httpd
Enter fullscreen mode Exit fullscreen mode

I copied it to production as-is. Two points matter: check daily (about 30 attempts within the 30-day window), and always reload right after renew. The old monthly crontab line gets deleted.

Before rolling it out, I verified the renewal path itself with a dry run:

$ certbot renew --dry-run
Congratulations, all simulated renewals succeeded
Enter fullscreen mode Exit fullscreen mode

This also confirms that the webroot challenge path (/.well-known/acme-challenge/) responds correctly under the current Apache config.

Final production check: ran the script manually — exit code 0, Reloaded The Apache HTTP Server appeared in journalctl, site returned HTTP 200. The certificate's expiry date didn't change since we're still outside the renewal window, but the full path — "try daily once within 30 days of expiry, apply immediately on success" — is now verified.

Takeaways

  • "There's a certbot renew in cron" ≠ "auto-renewal works." You need all three: daily frequency, a reload hook, and a dry-run verification
  • A monthly renew is a single coin flip. Certbot officially recommending twice a day is not an accident
  • Apache (and nginx) will not re-read certificates from disk by themselves. Renew and reload always go together
  • Don't panic over the expired default localhost.crt in ssl.conf — check which certificate path the vhost actually loads first

The biggest lesson for me: I couldn't explain why things had been fine so far. When the explanation turns out to be "logrotate happened to reload for us," that's luck, not operations. Normal behavior you can't explain should be treated as something to fix.

Top comments (0)