❯ TLS Certificates Expire at 3 AM: Automate Renewal Before It Bites

by Jonas Reyes — the builder's desk, Side Quest Studios
October 31, 2026

Look, nobody cares about your TLS certs until they're broken. Then suddenly, your marketing team is screaming, your customers are angry, and your revenue stream is looking like a dry riverbed. Guess when this always happens? 3 AM on a Sunday, right before a major holiday. You’ve been there, I’ve been there. The good news is, you don’t need to be there again. This isn't rocket science, and it sure as hell isn't "AI-powered predictive certificate management." This is basic system administration, the kind that keeps the lights on while the AI hype machine churns out more "graveyards".

Let's get this done.

The Cost of Manual Cert Management: Your Sleep and Your Revenue

I've seen it play out a hundred times. A new service goes live, someone manually generates a cert, maybe sets a calendar reminder. That reminder gets ignored, the person leaves the company, or some "urgent" new feature request pushes it to the back burner. Then, boom. Your API stops responding. Your website throws privacy errors. All because a tiny, text-based file, usually valid for 90 days or a year, hit its expiration date.

The cost isn't just a few hours of downtime. It's brand trust. It's missed sales. It's your phone ringing at 3 AM with a PagerDuty alert that just says "SSL_ERROR_BAD_CERT_DOMAIN." Your AI agents living in text messages aren't going to fix this. Your fancy new voice model isn't going to apologize for you. This is a fixable problem, and the fix is automation.

Why certbot and Let's Encrypt? Because It Just Works.

Forget proprietary CA dashboards, PDF forms, and annual renewal emails that look like phishing attempts. For 99% of use cases, Let's Encrypt is the answer. It's free, it's open, and it's built for automation. And certbot is the tool that makes it sing.

If you're running Apache or Nginx, certbot can often handle the entire process: obtaining the certificate, installing it, and configuring your web server to use it. On Debian/Ubuntu, it's usually:

sudo apt update
sudo apt install certbot python3-certbot-nginx # or python3-certbot-apache

Then, for Nginx:

sudo certbot --nginx -d example.com -d www.example.com

Or for Apache:

sudo certbot --apache -d example.com -d www.example.com

It will walk you through a few prompts, ask for an email for urgent notices (use a distribution list, not your personal address), and then configure everything. Done. No more manual cert generation, no more openssl req -new -newkey rsa:2048 -nodes -keyout example.key -out example.csr unless you absolutely need it for something obscure.

The "Renew" Step: The Cron Job That Saves Your Ass

The magic isn't just in getting the cert, it's in renewing it. Let's Encrypt certificates are typically valid for 90 days. certbot handles renewals gracefully. All you need is a cron job.

certbot usually installs a systemd timer or a cron job for you when you install it. Check /etc/cron.d/certbot or systemctl list-timers | grep certbot. If it's there, great. If not, you need to add it.

Open your crontab:

crontab -e

And add this line:

0 */12 * * * /usr/bin/certbot renew --quiet --post-hook "systemctl reload nginx" # or "systemctl reload apache2"

Let's break that down: * 0 */12 * * *: Runs twice a day (at the top of the hour, every 12 hours). This gives certbot plenty of opportunities to check for renewal and handle any transient network issues. * /usr/bin/certbot renew: This is the command that attempts to renew all managed certificates. * --quiet: Don't output anything to stdout unless an error occurs. Keep your logs clean. * --post-hook "systemctl reload nginx": This is crucial. After certbot successfully renews a certificate, it needs to tell your web server to load the new certificate files. A reload is usually sufficient; it reloads configuration without dropping active connections. Don't use restart unless you absolutely have to.

This cron job ensures your certificates are checked for renewal twice a day. certbot is smart enough to only renew them if they are close to expiration (typically within 30 days).

Beyond Web Servers: Automating Other Services

What if you're not running a standard web server? Maybe it's a custom Python API, an internal tool, or a Kafka cluster. You still need TLS. certbot can get you the certificates using the certonly command and the webroot or dns authenticator.

For example, to get a cert using webroot (assuming you can serve files from a specific directory):

sudo certbot certonly --webroot -w /var/www/html -d api.example.com

This will drop the certificate files in /etc/letsencrypt/live/api.example.com/. You'll get fullchain.pem, privkey.pem, and chain.pem. Your custom application then needs to be configured to use these files.

Your renewal hook becomes a little more involved. Instead of reloading Nginx, you'd reload your specific service. If it's a Python application, you might need to send it a SIGHUP or trigger a specific internal reload mechanism.

Example for a Python service running via systemd:

0 */12 * * * /usr/bin/certbot renew --quiet --post-hook "systemctl reload my-python-api.service"

Make sure your my-python-api.service unit file handles reload correctly. If not, restart might be your only option, but again, be mindful of connection drops.

The DNS Challenge: When Your Server Isn't Publicly Accessible

Sometimes, your server isn't directly exposed to the internet, or you're securing a wildcard domain (*.example.com). For these scenarios, the dns authenticator is your friend. This involves certbot creating a specific TXT record in your domain's DNS to prove ownership.

This is where certbot plugins for DNS providers come in. For Cloudflare, for instance:

sudo apt install python3-certbot-dns-cloudflare

Then, you'll need to create an API token for Cloudflare with DNS editing permissions and store it securely (e.g., in /root/.secrets/cloudflare.ini).

dns_cloudflare_api_token = YOUR_CLOUDFLARE_API_TOKEN

Then, you can request a cert:

sudo certbot certonly --dns-cloudflare --dns-cloudflare-credentials /root/.secrets/cloudflare.ini -d example.com -d *.example.com

The renewal process for DNS challenges is similar; certbot renew will use the same credentials to update the TXT record automatically. This is powerful for internal services or complex setups where direct HTTP challenges aren't feasible.

A Word on "Trustworthy AI" and "Scaling AI"

I see a lot of noise about "trustworthy AI" and "scaling AI" these days as government agencies try to wrap their heads around it. My take? If you can't trust your basic infrastructure to stay up, if your TLS certs are falling over at 3 AM, then any "trustworthy AI" you build on top of that is just a house of cards. Focus on the fundamentals first. Solid infrastructure, robust automation, and battle-tested open-source tools. That's how you build systems that actually scale and that you can actually trust.

Don't let an expiring TLS certificate be the reason your next big AI project ends up in the graveyard. Automate it, set it, and forget it. Your sleep, your customers, and your bottom line will thank you.

by Terminal King — the terminal, Side Quest Studios

References

💬 Discuss this article in the community — 0 replies →
Comments live on community.sqs.chat — one thread per article.