Skip to content

Commit 531f8b7

Browse files
Add the RENEWAL_INTERVAL environmental variable
After we handed over the entire decision making, of whether to renew a certificate or not, to certbot, it was now much easier to implement an environmental variable which allows the user to decide how often certbot should be triggered. Certbot will still only renew certificates if they are within 30 days of expiring, but with this addition we can let eager users trigger certbot more often to make sure they always have an up to date certificate. The documentation and examples have also been updated to explain how this new feture works.
1 parent b3d9dd9 commit 531f8b7

File tree

4 files changed

+57
-2
lines changed

4 files changed

+57
-2
lines changed

README.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,22 @@ files).
4747
[Docker](https://www.docker.com/) to function.
4848

4949

50+
## Available Environment Variables
51+
52+
### Reuired
53+
- `CERTBOT_EMAIL`: Your e-mail address. Used by Let's Encrypt to contact you in
54+
case of security issues.
55+
56+
### Optional
57+
- `STAGING`: Set to `1` to use Let's Encrypt's
58+
[staging servers](#initial-testing) (default: `0`)
59+
- `DHPARAM_SIZE`: The size of the
60+
[Diffie-Hellman parameters](#diffie-hellman-parameters)
61+
(default: `2048`)
62+
- `RSA_KEY_SIZE`: The size of the RSA encryption keys (default: `2048`)
63+
- `RENEWAL_INTERVAL`: Time interval between certbot's
64+
[renewal checks](#renewal-check-interval) (default: `8d`)
65+
5066
## Run with `docker run`
5167

5268
### Build it yourself
@@ -103,6 +119,7 @@ services:
103119
- STAGING=0
104120
- DHPARAM_SIZE=2048
105121
- RSA_KEY_SIZE=2048
122+
- RENEWAL_INTERVAL=8d
106123
ports:
107124
- 80:80
108125
- 443:443
@@ -193,6 +210,36 @@ certificate request from the above file will then become something like this
193210
certbot ... -d yourdomain.org -d www.yourdomain.org -d sub.yourdomain.org
194211
```
195212

213+
### Renewal check interval
214+
This container will automatically start a certbot certificate renewal check
215+
after the time duration that is defined in the environmental variable
216+
`RENEWAL_INTERVAL` has passed. After certbot has done its stuff, the code will
217+
return and wait the defined time before triggering again.
218+
219+
This process is very simple, and is just a `while [ true ];` loop with a `sleep`
220+
at the end:
221+
222+
```bash
223+
while [ true ]; do
224+
# Run certbot...
225+
sleep "$RENEWAL_INTERVAL"
226+
done
227+
```
228+
229+
So when setting the environmental variable, it is possible to use any string
230+
that is recognized by `sleep`, e.g. `3600` or `60m` or `1h`. Read more about
231+
which values that are allowed in its
232+
[manual](http://man7.org/linux/man-pages/man1/sleep.1.html).
233+
234+
The default is `8d`, since this allows for multiple retries per month, while
235+
keeping the output in the logs at a very low level. If nothing needs to be
236+
renewed certbot won't do anything, so it should be no problem setting it lower
237+
if you want to. The only thing to think about is to not to make it longer than
238+
one month, because then you would
239+
[miss the window](https://community.letsencrypt.org/t/solved-how-often-to-renew/13678)
240+
where certbot would deem it necessary to update the certificates.
241+
242+
196243
### Diffie-Hellman parameters
197244
Regarding the Diffie-Hellman parameter it is recommended that you have one for
198245
your server. However, you can make a config file without it and Nginx will work

example/docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ services:
99
- STAGING
1010
- DHPARAM_SIZE
1111
- RSA_KEY_SIZE
12+
- RENEWAL_INTERVAL
1213
ports:
1314
- 80:80
1415
- 443:443

src/.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ [email protected]
55
STAGING=0
66
DHPARAM_SIZE=2048
77
RSA_KEY_SIZE=2048
8+
RENEWAL_INTERVAL=8d

src/scripts/entrypoint.sh

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ echo "Starting the Nginx service"
2525
nginx -g "daemon off;" &
2626
NGINX_PID=$!
2727

28+
# Make sure a renewal interval is set before continuing.
29+
if [ -z "$RENEWAL_INTERVAL" ]; then
30+
echo "RENEWAL_INTERVAL unset, using default of '8d'"
31+
RENEWAL_INTERVAL='8d'
32+
fi
33+
2834
# Instead of trying to run 'cron' or something like that, just sleep and
2935
# execute the 'certbot' script.
3036
(
@@ -33,8 +39,8 @@ while [ true ]; do
3339
echo "Run certbot!"
3440
/scripts/run_certbot.sh
3541

36-
echo "Certbot will now sleep for 8 days..."
37-
sleep 8d
42+
echo "Certbot will now sleep..."
43+
sleep "$RENEWAL_INTERVAL"
3844
done
3945
) &
4046

0 commit comments

Comments
 (0)