ACME certificate renewal automation that does not fail quietly
Certificate renewal automation with the ACME protocol replaces a certificate before it expires with no person involved: a scheduler starts the client, the client proves control of the domain and receives a new certificate, and a hook reloads the server. When it fails, it fails quietly: the old certificate keeps working until its end date. This page takes each step for Certbot on Linux, with a systemd timer or cron, and shows how to test the cycle and catch a failure from outside in time. Knowing which certificates exist and who answers for each, including those no timer covers, is certificate lifecycle management.
Quick facts
- When Certbot renews
- with less than a third of the lifetime left, or half for lifetimes of 10 days or less; earlier if the authority's ARI window says so [1][2]
- Schedule
- a systemd timer or a cron job that runs
certbot renew[1] - Reload
- a deploy hook, which runs only after a successful renewal [1]
- Monitor
- the certificate each hostname serves, checked from outside
The four steps that can fail
Automated renewal is a chain of four steps, and each can break on its own.
The schedule. Something must run
certbot renewperiodically. Most Certbot installations come with that scheduled task preconfigured [1]. A timer disabled during maintenance, a container rebuilt without it or a new server set up without one stops renewal with no error.The challenge. Validation must still pass. A redirect added months ago, an application that takes over
/.well-known/, a firewall change or rotated DNS credentials can each break the next renewal. How the challenge types differ is on ACME. A certificate obtained with Certbot's manual plugin does not renew automatically unless authentication hook scripts are set [1]. For a Let's Encrypt wildcard SSL certificate, that means a DNS plugin or a hook that sets the TXT record.The deployment. The new certificate must reach the place that serves it. Certbot writes the files under its configuration directory [1]; with a load balancer, a container image or several servers, a separate step copies them. Renewal that succeeds while deployment fails looks like success.
The reload. The server has to load the new files: nginx, for one, kept serving the old certificate after both files were replaced on disk, until
nginx -s reload, in our runs for the nginx guide [12].
From outside, all four failures look the same: the served certificate keeps its old dates until expiry, which is why the monitoring below checks that certificate, not the renewal job.
When renewal should happen
Certbot's renew command acts only on certificates that are ready for renewal. Since Certbot 4.0.0 that means less than a third of the lifetime remains before expiry, or less than half for certificates with a lifetime of 10 days or less; before 4.0.0 it was a fixed 30 days [1]. In our runs, a test certificate with a 120-second lifetime was skipped right after issuance and renewed once less than half of it was left [12]. The renew_before_expiry field of a certificate's renewal configuration still overrides the default [2]. Because renew usually takes no action, a cron job or a systemd timer can run it as often as you like [1].
When the authority suggests a time
ACME Renewal Information, ARI, a standards-track extension defined in RFC 9773, lets an ACME server publish a suggested renewal window for each certificate and move it earlier, for example ahead of a mass revocation; the client should pick a random time inside it. Cron-based clients may need to run more often to see a window in time, and then have to remember failures so they do not retry without backoff [3]. Certbot checks ARI from version 4.1.0 when the server supports it, and an early ARI window overrides a later renew_before_expiry [2]. Renewing a Let's Encrypt SSL certificate works this way: the authority asks clients to check ARI at least twice a day, run at a random time and retry with backoff [8].
Shorter lifetimes leave less room. Under the CA/Browser Forum ballot SC-081v3, the maximum lifetime of a publicly trusted certificate falls in steps to 47 days for certificates issued from 15 March 2029 [9]. With Certbot's default threshold, such a certificate becomes due with under 16 days left, and from then on a renewal that does not happen is an outage in under 16 days.
Schedule renewal with a systemd timer or cron
Check first whether a scheduled task exists: Certbot's guide says to look for certbot renew in the system crontab (/etc/crontab or /etc/cron.*/*) or in systemctl list-timers [1].
A systemd timer
A systemd timer is a .timer unit that activates the service unit of the same name [4]. A minimal certbot-renew.timer:
[Timer]
OnCalendar=*-*-* 00,12:00:00
RandomizedDelaySec=1h
Persistent=true
[Install]
WantedBy=timers.targetAnd the certbot-renew.service it starts:
[Service]
Type=oneshot
ExecStart=/usr/local/bin/certbot renew -qOnCalendar= sets wall-clock times. RandomizedDelaySec= adds a random delay of up to the given time before each run. Persistent=true stores the time of the last run on disk and starts a missed renewal run once the timer is active again, for example after the machine was powered off [4]. systemd-analyze calendar shows when an expression elapses next, and systemd-analyze verify checks the units [5]; in our runs, verify reported Command /usr/local/bin/certbot is not executable on a machine where Certbot lived elsewhere [12]. Afterwards, systemctl list-timers shows the last and next run of each timer [5]. A LAST that is days old on a twice-daily timer means the schedule has stopped, and the certificate is heading for its expiry unrenewed.
A cron job
To set up renewal yourself, Certbot's guide gives a line that adds a cron job to /etc/crontab: twice a day, after a random sleep of up to an hour [1]. Add the reload as a deploy hook, here or in the hooks directory below.
SLEEPTIME=$(awk 'BEGIN{srand(); print int(rand()*(3600+1))}'); echo "0 0,12 * * * root sleep $SLEEPTIME && certbot renew -q" | sudo tee -a /etc/crontab > /dev/nullcron mails any output of a command to the crontab's owner, or to MAILTO [6]. With -q, Certbot prints only errors [1], so mail comes only when a certificate failed to renew; in our runs, a run with nothing due printed nothing [12]. A % in the command becomes a newline unless escaped with a backslash, and the rest goes to the command as input [6]: a --deploy-hook that calls date +%F in the crontab line breaks there.
Reload the server with a deploy hook
A deploy hook runs once for each certificate that was successfully issued, including on later renewals. Pre and post hooks run before and after each attempt to renew a certificate that is due [1]. The reload belongs in the deploy hook:
$ certbot renew --deploy-hook "systemctl reload nginx"Options of a successful renewal are saved for that certificate's future renewals [1]; in our runs a saved post hook ran on the next renewal without being passed [12]. Executable files in /etc/letsencrypt/renewal-hooks/deploy/ run as deploy hooks too, in alphabetical order [1]. Inside the hook, $RENEWED_LINEAGE points to the directory with the new files and $RENEWED_DOMAINS lists the names [1].
Renewals reuse the same state, including the ACME account key and its contact email.
A failing hook does not fail the run: Certbot prints the error, carries on, and the hook alone does not make the exit status non-zero [1]. In our runs, a deploy hook that exited with 1 printed Hook 'deploy-hook' reported error code 1, then Congratulations, all renewals succeeded, and Certbot exited with 0 [12]. The exit status is 1 only when a renewal attempt failed, and 0 when nothing was due [1], so a script that reads it cannot tell a renewal from a quiet day. Have the deploy hook report its own result.
Test the whole cycle before relying on it
A dry run renews against the Let's Encrypt staging server, or the server given with --server, and saves no certificate to disk [1]. Pre and post hooks run; deploy hooks do not, unless --run-deploy-hooks is added, and then only if the dry run succeeds, with the current certificate rather than the test one [1]. In our runs, after certbot renew --dry-run the hook log held the pre and post hooks only and the certificate file was unchanged; with --run-deploy-hooks the deploy hook ran too [12]. A plain dry run tests the renewal command and the challenge, not the reload, and not the schedule, since you started it by hand. To include the reload:
$ certbot renew --dry-run --run-deploy-hooksDebug against the staging environment, not production: Let's Encrypt recommends it to reduce the chance of running into rate limits [7].
Then confirm one real renewal from outside. --force-renewal ignores the expiry date; it is not for a daily job, because every run would renew every certificate and quickly reach the authority's rate limit [1]. After it, check the dates the hostname serves:
$ openssl s_client -connect example.com:443 -servername example.com </dev/null 2>/dev/null | openssl x509 -noout -datesRepeat the test after any change to the server, the routing, the DNS provider or the credentials.
Moving off Certbot on Windows changes who schedules renewal, so check that renewal is scheduled once the new client is in place.
Monitor the outcome, not the process
Monitoring the renewal job tells you whether it thinks it succeeded. Monitoring the certificate tells you what visitors get. They differ in exactly the cases that matter: a job that stopped being scheduled reports nothing, and a deploy hook that failed still ends in a success message.
Ask each hostname which certificate it presents and how long it has left, from a machine that does not share credentials or hardware with the renewal system:
$ openssl s_client -connect example.com:443 -servername example.com </dev/null 2>/dev/null | openssl x509 -noout -checkend 1209600-checkend exits non-zero when the certificate expires within the given seconds, here 14 days [10]. Any monitoring system can run it, or an equivalent HTTPS check, on a schedule. On Bridge CDN, renewal is attempted ahead of expiry and the platform does not publish a guaranteed time for issuing or renewal; its advice is the same: keep an outside check on what your hostnames present.
Check every certificate in service, not only the website's: mail servers, APIs, load balancers, devices. Certificate Transparency logs, described in RFC 6962, publicly record certificates as they are issued or observed [11], which helps find the forgotten ones.
Alert on the right threshold
Alerting the day before expiry is too late. Alerting on every failed attempt is noise, because certbot renew checks each certificate again on its next run [1].
Set the alert below the point where renewal should already have happened. Certbot renews with a third of the lifetime left [1], so an alert at a quarter of the lifetime leaves the automation several scheduled runs to succeed and you days to act: 50 days for a 200-day certificate, 25 for a 100-day one and, rounded up, 12 for a 47-day one.
What to do when it does fail
Restore service first. Obtain and install a certificate by whatever works now, as described on renewal.
Find which step failed. The table maps what you see to the step; Certbot keeps its logs in
/var/log/letsencrypt[1].Ask why nobody noticed. That is a different question from why it failed. If monitoring existed and did not fire, fix the monitoring.
| What you see | Step | Where to look |
|---|---|---|
No new run in the log, an old LAST in systemctl list-timers | schedule | the timer or crontab line; systemd-analyze verify [5] |
Failed to renew certificate, All renewals failed, exit 1 | challenge or the authority | the error text; a dry run [1][12] |
Congratulations, all renewals succeeded, old dates served | deployment or reload | Hook 'deploy-hook' reported error code; the copy step [12] |
| New files on disk, old dates served, no deploy hook | reload | add a deploy hook [1] |
When the authority could not be reached in our runs, Certbot exited with 1 and left the certificate file unchanged [12]. Choosing a client that can deploy and reload on its own removes two of the four steps; see ACME clients.
FAQ
Why does automated certificate renewal fail silently?
Because nothing changes when it stops. The existing certificate keeps working until it expires, long after the change that caused the failure.
What should I monitor?
The certificate each hostname serves and how long it has left, checked from outside the server. Alert when it passes the point where it should have been renewed.
What is ACME ARI?
ACME Renewal Information, defined in RFC 9773: a certificate authority publishes a suggested renewal window for each certificate and can move it earlier, for example ahead of a mass revocation. [3]
Sources
Certbot changelog, 4.0.0 and 4.1.0.
RFC 9773, ACME Renewal Information.
systemctl(1), systemd-analyze(1).
crontab(5), cron(8), Debian.
CA/Browser Forum, Ballot SC-081v3; BR §6.3.2.
OpenSSL 3.0, openssl-x509.
RFC 6962, Certificate Transparency.
Our runs: Certbot 5.8.0 against Pebble 2.10.1, a local ACME test server, with test certificates; nginx 1.30.6 for the nginx guide.