# How to continuously create/renew certificates without hitting limits?

**URL:** <https://community.letsencrypt.org/t/how-to-continuously-create-renew-certificates-without-hitting-limits/184562>\
**Category:** Help\
**Created:** [September 16, 2022, 9:45am UTC](https://community.letsencrypt.org/t/how-to-continuously-create-renew-certificates-without-hitting-limits/184562 "2022-09-16T09:45:39Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![bluepuma77](https://sea3.discourse-cdn.com/letsencrypt/user_avatar/community.letsencrypt.org/bluepuma77/32/63997_2.png) [@bluepuma77](https://community.letsencrypt.org/u/bluepuma77)\
**Post date:** [September 16, 2022, 9:45am UTC](https://community.letsencrypt.org/t/how-to-continuously-create-renew-certificates-without-hitting-limits/184562/1 "2022-09-16T09:45:39Z")

</div>

We are using Traefik and Docker Swarm to run our SaaS applications. Traefik creates routing to the services/containers on the-fly through service discovery, polling Swarm every 15 seconds. For those routes we want to create Let's Encrypt certificates. (We can't use Traefik own integrated process because it's not easily cluster-able.)

We can get the list of hosts from Traefik, polling every 15 seconds for updates:

```nohighlight
# curl -s http://traefik:8080/api/http/routers | pcregrep -o '(?<=Host\(`).*?(?=`\))' | sort | uniq
admin.example.com
dashboard.example.com
client_01.example.com
client_02.example.com

```

When I get a list of hosts every 15 seconds, I don't want to run `certbot certonly -standalone` every time, because it will register for every run (limits!) and create new certificates (limits!), even if I have valid certificates present. `certbot renew -standalone` just threw errors on me.

**How should we structure a process that is triggered every 15 seconds to create/renew Let's Encrypt certificates?** `certbot` gets a list of hosts, should check if certs do not exist or need renewal, only then register and create/update the certificates, otherwise just exit. **Is there a single command to do this?** Should we do this with every host individually or in batch?

---

<div class="post-metadata">

**Author:** ![rg305](https://sea3.discourse-cdn.com/letsencrypt/user_avatar/community.letsencrypt.org/rg305/32/91314_2.png) [@rg305](https://community.letsencrypt.org/u/rg305)\
**Post date:** [September 16, 2022, 3:10pm UTC](https://community.letsencrypt.org/t/how-to-continuously-create-renew-certificates-without-hitting-limits/184562/2 "2022-09-16T15:10:52Z")

</div>

It sounds like you might hit some limit if you are continually adding or removing names from the list.  
Your best case scenario (IMO) would be to obtain individual certs.  
That way the only time `certbot` would be required to do anything is when a new name is added.  
OR  
Only concern yourself with adding names to the list [not removing any - since such names may return within their already covered period].

In any case, it will eventually require a name cleanup process [to remove any expired names/certs].

> [@bluepuma77](#):
>
> Should we do this with every host individually or in batch?

If they will all be serving the same set of names, then they could use the exact same cert(s).  
Certs can be copied from system to system.

---

<div class="post-metadata">

**Author:** ![bluepuma77](https://sea3.discourse-cdn.com/letsencrypt/user_avatar/community.letsencrypt.org/bluepuma77/32/63997_2.png) [@bluepuma77](https://community.letsencrypt.org/u/bluepuma77)\
**Post date:** [September 16, 2022, 3:41pm UTC](https://community.letsencrypt.org/t/how-to-continuously-create-renew-certificates-without-hitting-limits/184562/3 "2022-09-16T15:41:20Z")

</div>

@rg305 Thanks for you extensive response.

What I don't understand is if certbot has a single _create-or-renew_ command option which I can execute every minute without hitting limits.

```nohighlight
certbot create-or-renew --standalone --non-interactive -d www.example.com

```

Meaning `certbot` will only register and create a certificate when there is no certificate file OR it's already 60 days old. Otherwise `certbot` will just quit without doing anything.

Or do I need to create this logic outside of `certbot` myself?

---

<div class="post-metadata">

**Author:** ![rg305](https://sea3.discourse-cdn.com/letsencrypt/user_avatar/community.letsencrypt.org/rg305/32/91314_2.png) [@rg305](https://community.letsencrypt.org/u/rg305)\
**Post date:** [September 16, 2022, 3:47pm UTC](https://community.letsencrypt.org/t/how-to-continuously-create-renew-certificates-without-hitting-limits/184562/4 "2022-09-16T15:47:46Z")

</div>

Sounds like you need to create your own logic for this, like:  
`certbot renew --standalone --non-interactive -d www.example.com [- d example.com]`  
If not found, then "create" it:  
`certbot --standalone --non-interactive -d www.example.com [- d example.com]`  
[the "if not found" should be detectable via the exit code]

Otherwise, you could also just do both and ignore all errors.

---

<div class="post-metadata">

**Author:** ![bluepuma77](https://sea3.discourse-cdn.com/letsencrypt/user_avatar/community.letsencrypt.org/bluepuma77/32/63997_2.png) [@bluepuma77](https://community.letsencrypt.org/u/bluepuma77)\
**Post date:** [September 16, 2022, 3:54pm UTC](https://community.letsencrypt.org/t/how-to-continuously-create-renew-certificates-without-hitting-limits/184562/5 "2022-09-16T15:54:55Z")

</div>

Thanks. My challenge is that `certbot certonly --standalone` will register and create a new cert every time it's called. If I call it every 15 seconds it is unnecessary load and it will hit the limits.

Will check `certbot renew` and exit codes...

---

<div class="post-metadata">

**Author:** ![jvanasco](https://sea3.discourse-cdn.com/letsencrypt/user_avatar/community.letsencrypt.org/jvanasco/32/55900_2.png) [@jvanasco](https://community.letsencrypt.org/u/jvanasco)\
**Post date:** [September 16, 2022, 4:00pm UTC](https://community.letsencrypt.org/t/how-to-continuously-create-renew-certificates-without-hitting-limits/184562/6 "2022-09-16T16:00:50Z")

</div>

> [@bluepuma77](#):
>
> What I don't understand is if certbot has a single _create-or-renew_ command option which I can execute every minute without hitting limits.

Certbot is designed to be used by persistent servers, not multi-node scaling systems or adaptive deployments. You should be using another client - off the shelf or homegrown - or build a specialized system to control Certbot.

There are several servers and gateways that offer cloud-storage (so you can share certs) and autocert functionality (certificate on demand). There are also some certificate managers that may be of use.

We developed an in-house acme-client+certificate manager and nginx module for:

- API driven certificates
- autoloading into Nginx
- SQL based Certificate Management

I opensourced it a while back, but the public repo is out of date [GitHub - aptise/peter\_sslers: or how i stopped worrying and learned to love the ssl certificate](https://github.com/aptise/peter_sslers)

there may still be useful materials in there for you.

---

<div class="post-metadata">

**Author:** ![Osiris](https://avatars.discourse-cdn.com/v4/letter/o/839c29/32.png) [@Osiris](https://community.letsencrypt.org/u/Osiris)\
**Post date:** [September 16, 2022, 4:04pm UTC](https://community.letsencrypt.org/t/how-to-continuously-create-renew-certificates-without-hitting-limits/184562/7 "2022-09-16T16:04:59Z")

</div>

Why don't you put a wildcard cert per domain on Traefik?

---

<div class="post-metadata">

**Author:** ![petercooperjr](https://sea3.discourse-cdn.com/letsencrypt/user_avatar/community.letsencrypt.org/petercooperjr/32/84698_2.png) [@petercooperjr](https://community.letsencrypt.org/u/petercooperjr)\
**Post date:** [September 16, 2022, 4:08pm UTC](https://community.letsencrypt.org/t/how-to-continuously-create-renew-certificates-without-hitting-limits/184562/8 "2022-09-16T16:08:15Z")

</div>

You probably also want to be sure to read through the Integration Guide

> **[Integration Guide - Let's Encrypt](https://letsencrypt.org/docs/integration-guide/)**
>
> This document contains helpful advice if you are a hosting provider or large website integrating Let’s Encrypt, or you are writing client software for Let’s Encrypt.
> Plan for Change Both Let’s Encrypt and the Web PKI will continue...

I agree that you might be better served by some client other than Certbot.

---

<div class="post-metadata">

**Author:** ![bluepuma77](https://sea3.discourse-cdn.com/letsencrypt/user_avatar/community.letsencrypt.org/bluepuma77/32/63997_2.png) [@bluepuma77](https://community.letsencrypt.org/u/bluepuma77)\
**Post date:** [September 16, 2022, 4:38pm UTC](https://community.letsencrypt.org/t/how-to-continuously-create-renew-certificates-without-hitting-limits/184562/9 "2022-09-16T16:38:37Z")

</div>

> [@Osiris](#):
>
> Why don't you put a wildcard cert per domain on Traefik?

I have no API for our DNS service and I don't want to manually edit DNS every couple of weeks.

---

<div class="post-metadata">

**Author:** ![bluepuma77](https://sea3.discourse-cdn.com/letsencrypt/user_avatar/community.letsencrypt.org/bluepuma77/32/63997_2.png) [@bluepuma77](https://community.letsencrypt.org/u/bluepuma77)\
**Post date:** [September 16, 2022, 4:44pm UTC](https://community.letsencrypt.org/t/how-to-continuously-create-renew-certificates-without-hitting-limits/184562/10 "2022-09-16T16:44:52Z")

</div>

Oh, now it gets complicated

```nohighlight
#certbot renew -v --standalone --non-interactive --test-cert -m mail@example.com -d client_01.example.com
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Currently, the renew verb is capable of either renewing all installed certificates that are due to be renewed or renewing a single certificate specified by its name. If you would like to renew specific certificates by their domains, use the certonly command instead. The renew verb may provide other options for selecting certificates to renew in the future.

```

So I manually need to go through all cert files to see if a domain already has a certificate.

---

<div class="post-metadata">

**Author:** ![Osiris](https://avatars.discourse-cdn.com/v4/letter/o/839c29/32.png) [@Osiris](https://community.letsencrypt.org/u/Osiris)\
**Post date:** [September 16, 2022, 4:50pm UTC](https://community.letsencrypt.org/t/how-to-continuously-create-renew-certificates-without-hitting-limits/184562/11 "2022-09-16T16:50:32Z")

</div>

> [@bluepuma77](#):
>
> I have no API for our DNS service and I don't want to manually edit DNS every couple of weeks.

That's not really a problem, you can use CNAME resource records to delegate the challenge to a specific zone that can answer specifically for ACME challenges using software that does have an API, such as [acme-dns](https://github.com/joohoi/acme-dns).

Note that the Traefik documentation actually mentions acme-dns: [Traefik Let's Encrypt Documentation - Traefik](https://doc.traefik.io/traefik/https/acme/#providers)

---

<div class="post-metadata">

**Author:** ![bluepuma77](https://sea3.discourse-cdn.com/letsencrypt/user_avatar/community.letsencrypt.org/bluepuma77/32/63997_2.png) [@bluepuma77](https://community.letsencrypt.org/u/bluepuma77)\
**Post date:** [September 16, 2022, 4:52pm UTC](https://community.letsencrypt.org/t/how-to-continuously-create-renew-certificates-without-hitting-limits/184562/12 "2022-09-16T16:52:29Z")

</div>

My plan is to create a Traefik-Certbot Docker container that

1. Fetches all domains from Traefik every 15 seconds
2. Creates new certificates if required
3. Updates old certificates if required
4. Provides a [traefik-dynamic.yml](https://doc.traefik.io/traefik/https/tls/) via HTTP with all certs inline  
(Traefik will fetch this every 15 seconds for LE certificate updates)

Because Traefik has integrated Let's Encrypt it seems no one has done this before. I run Traefik in Docker Swarm and the clustering is breaking the integrated mechanism. I assume normal people just migrate to k8s 😉

---

<div class="post-metadata">

**Author:** ![MikeMcQ](https://sea3.discourse-cdn.com/letsencrypt/user_avatar/community.letsencrypt.org/mikemcq/32/52772_2.png) [@MikeMcQ](https://community.letsencrypt.org/u/MikeMcQ)\
**Post date:** [September 16, 2022, 5:01pm UTC](https://community.letsencrypt.org/t/how-to-continuously-create-renew-certificates-without-hitting-limits/184562/13 "2022-09-16T17:01:17Z")

</div>

> [@bluepuma77](#):
>
> Because Traefik has integrated Let's Encrypt it seems no one has done this before.

Are you sure? 🙂 Have you asked on a [Traefik forum](https://community.traefik.io)? Maybe there is a better architecture.

The outline you describe looks to require complex error handling.

---

<div class="post-metadata">

**Author:** ![petercooperjr](https://sea3.discourse-cdn.com/letsencrypt/user_avatar/community.letsencrypt.org/petercooperjr/32/84698_2.png) [@petercooperjr](https://community.letsencrypt.org/u/petercooperjr)\
**Post date:** [September 16, 2022, 5:10pm UTC](https://community.letsencrypt.org/t/how-to-continuously-create-renew-certificates-without-hitting-limits/184562/14 "2022-09-16T17:10:02Z")

</div>

I have no experience with Traefik, but it sounds to me like the automatically-get-certs-on-demand approach is what systems like Caddy do. You might just want your HTTPS to be in front of your systems using something like that which can handle all the certificates itself.

---

<div class="post-metadata">

**Author:** ![rg305](https://sea3.discourse-cdn.com/letsencrypt/user_avatar/community.letsencrypt.org/rg305/32/91314_2.png) [@rg305](https://community.letsencrypt.org/u/rg305)\
**Post date:** [September 16, 2022, 5:19pm UTC](https://community.letsencrypt.org/t/how-to-continuously-create-renew-certificates-without-hitting-limits/184562/15 "2022-09-16T17:19:12Z")

</div>

Try changing:  
`-d client_01.example.com`  
To:  
`--cert-name client_01.example.com`

---

<div class="post-metadata">

**Author:** ![bluepuma77](https://sea3.discourse-cdn.com/letsencrypt/user_avatar/community.letsencrypt.org/bluepuma77/32/63997_2.png) [@bluepuma77](https://community.letsencrypt.org/u/bluepuma77)\
**Post date:** [September 16, 2022, 5:36pm UTC](https://community.letsencrypt.org/t/how-to-continuously-create-renew-certificates-without-hitting-limits/184562/17 "2022-09-16T17:36:42Z")

</div>

> [@MikeMcQ](#):
>
> Are you sure? 🙂 Have you asked on a [Traefik forum](https://community.traefik.io)?

Official clustered Let's Encrypt is only supported by TraefikEE. And after a call they tell you pricing starts at €3000/year.

---

<div class="post-metadata">

**Author:** ![bluepuma77](https://sea3.discourse-cdn.com/letsencrypt/user_avatar/community.letsencrypt.org/bluepuma77/32/63997_2.png) [@bluepuma77](https://community.letsencrypt.org/u/bluepuma77)\
**Post date:** [September 16, 2022, 7:22pm UTC](https://community.letsencrypt.org/t/how-to-continuously-create-renew-certificates-without-hitting-limits/184562/18 "2022-09-16T19:22:23Z")

</div>

> [@rg305](#):
>
> Try changing:  
> `-d client_01.example.com`  
> To:  
> `--cert-name client_01.example.com`

Excellent, that works! First step to a working solution 🙂

```nohighlight
# run in certbot Docker container
apk add curl
apk add pcre-tools

/bin/sleep 20 # for service discovery to establish routing

DOMAINS=$(curl --silent --max-time 5 http://user:pass@traefik:8080/api/http/routers | \
  pcregrep -o '(?<=Host\(`).*?(?=`\))' | sort | uniq)

for DOM in $DOMAINS; do 
  echo RENEW $DOM
  certbot renew --standalone --non-interactive --agree-tos --no-eff-email --test-cert --cert-name $DOM
  if [$? -ne 0]; then
    echo CREATE $DOM
    certbot certonly --standalone --non-interactive --agree-tos --no-eff-email --test-cert -m mail@example.com -d $DOM
  fi
done

```

---

<div class="post-metadata">

**Author:** ![rg305](https://sea3.discourse-cdn.com/letsencrypt/user_avatar/community.letsencrypt.org/rg305/32/91314_2.png) [@rg305](https://community.letsencrypt.org/u/rg305)\
**Post date:** [September 16, 2022, 7:33pm UTC](https://community.letsencrypt.org/t/how-to-continuously-create-renew-certificates-without-hitting-limits/184562/19 "2022-09-16T19:33:31Z")

</div>

Did that just save you from?:

> [@bluepuma77](#):
>
> €3000/year

LOL

---

<div class="post-metadata">

**Author:** ![schoen](https://sea3.discourse-cdn.com/letsencrypt/user_avatar/community.letsencrypt.org/schoen/32/79_2.png) [@schoen](https://community.letsencrypt.org/u/schoen)\
**Post date:** [September 18, 2022, 7:27am UTC](https://community.letsencrypt.org/t/how-to-continuously-create-renew-certificates-without-hitting-limits/184562/20 "2022-09-18T07:27:59Z")

</div>

> [@bluepuma77](#):
>
> `certbot create-or-renew --standalone --non-interactive -d www.example.com`

This should work with the `--cert-name` suggestion. The fullest form would be something like

`certbot certonly --standalone --non-interactive --keep-until-expiring --cert-name www.example.com -d www.example.com`

The `--keep-until-expiring` tells it _not_ to renew if the certificate exists and is not very old. (This might already be the default with `--non-interactive`, so it might be redundant to specify it.)

This command will obtain a new certificate if no such certificate exists, exit immediately if it exists and is not due for renewal, and renew it if it exists and is due for renewal (by default, if it is expiring in \<30 days from now).

---

<div class="post-metadata">

**Author:** ![bluepuma77](https://sea3.discourse-cdn.com/letsencrypt/user_avatar/community.letsencrypt.org/bluepuma77/32/63997_2.png) [@bluepuma77](https://community.letsencrypt.org/u/bluepuma77)\
**Post date:** [September 24, 2022, 5:21am UTC](https://community.letsencrypt.org/t/how-to-continuously-create-renew-certificates-without-hitting-limits/184562/21 "2022-09-24T05:21:05Z")

</div>

> [@schoen](#):
>
> --keep-until-expiring

This is awesome, it works, thank you!

[Next page](https://community.letsencrypt.org/t/how-to-continuously-create-renew-certificates-without-hitting-limits/184562.md?page=2)
