I'm having difficulties running certbot renewals via cronjob in one particular environment. I have two other environments that the cronjob renewals run fine. Only in this one have I received problems. If I set the cronjob a few minutes or hours ahead, it typically runs fine. If I set it to run a week ahead, I run into the issue I describe below.
My domain is: dev.elselabs.io
I ran this command:
I run a CRONTAB which runs this script:
echo "\n BEGINNING REFRESH \n";
# Print the current date and time
dt=$(date '+%d/%m/%Y %H:%M:%S');
echo "$dt"
# Request a Lets Encrypt certificate using the offical Docker image
# for provided domain
DOMAIN=$1;
echo "\n\033[0;33m=> Requesting CERT for $DOMAIN ------------------------------\033[0";
docker run --name certbot -v /etc/letsencrypt:/etc/letsencrypt -v /var/www/html:/var/www/html certbot/certbot certonly \
--webroot --webroot-path=/var/www/html -d $DOMAIN --force-renewal --verbose
# GET Nginx docker container name, then stop and remove it
# The automatically generated Nginx container will apply the new CERT
CONTAINER_NAME=$(exec docker ps --format "{{.Names}}" | grep nginx);
echo "\n\033[0;33m=> Stopping $CONTAINER_NAME ------------------------------\033[0m";
docker stop $CONTAINER_NAME
echo "\n\033[0;33m=> Removing $CONTAINER_NAME ------------------------------\033[0m";
docker rm $CONTAINER_NAME;
echo "\n REFRESH COMPLETE \n";
The CRONTAB looks like this:
0 0 * * FRI /usr/src/nginx/refresh_cert.sh dev.elselabs.io >> /usr/src/nginx/refresh_cert.err
It produced this output:
When the command is run from the terminal, it looks like this:
\n BEGINNING REFRESH \n
02/02/2024 15:19:07
\n\033[0;33m=> Requesting CERT for dev.elselabs.io ------------------------------\033[0
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator webroot, Installer None
Renewing an existing certificate for dev.elselabs.io
Successfully received certificate.
Certificate is saved at: /etc/letsencrypt/live/dev.elselabs.io/fullchain.pem
Key is saved at: /etc/letsencrypt/live/dev.elselabs.io/privkey.pem
This certificate expires on 2024-05-02.
These files will be updated when the certificate renews.
NEXT STEPS:
- The certificate will need to be renewed before it expires. Certbot can automatically renew the certificate in the background, but you may need to take steps to enable that functionality. See https://certbot.org/renewal-setup for instructions.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
If you like Certbot, please consider supporting our work by:
* Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate
* Donating to EFF: https://eff.org/donate-le
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
\n\033[0;33m=> Stopping development_nginx.1.zq9ajwgosjmzxwp9if1xkswqn ------------------------------\033[0m
development_nginx.1.zq9ajwgosjmzxwp9if1xkswqn
\n\033[0;33m=> Removing development_nginx.1.zq9ajwgosjmzxwp9if1xkswqn ------------------------------\033[0m
development_nginx.1.zq9ajwgosjmzxwp9if1xkswqn
\n REFRESH COMPLETE \n
When the crontab runs it, it looks like this:
\n BEGINNING REFRESH \n
02/02/2024 00:00:01
\n\033[0;33m=> Requesting CERT for dev.elselabs.io ------------------------------\033[0
Renewing an existing certificate for dev.elselabs.io
\n\033[0;33m=> Stopping development_nginx.1.3al3392m9fjk44nzgb5dwcifi ------------------------------\033[0m
development_nginx.1.3al3392m9fjk44nzgb5dwcifi
\n\033[0;33m=> Removing development_nginx.1.3al3392m9fjk44nzgb5dwcifi ------------------------------\033[0m
development_nginx.1.3al3392m9fjk44nzgb5dwcifi
\n REFRESH COMPLETE \n
I allowed the container to remain on the server so I could inspect the logs within it. They look like this:
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator webroot, Installer None
Renewing an existing certificate for dev.elselabs.io
An unexpected error occurred:
No order for ID 241139202797
Ask for help or search for solutions at https://community.letsencrypt.org. See the logfile /var/log/letsencrypt/letsencrypt.log or re-run Certbot with -v for more details.
My web server is (include version):
I'm running NGINX in a container. nginx:stable-alpine
The operating system my web server runs on is (include version):
I'm running this on Ubuntu 22.
My hosting provider, if applicable, is:
This infrastructure runs within a DigitalOcean droplet
I can login to a root shell on my machine (yes or no, or I don't know):
Yes
I'm using a control panel to manage my site (no, or provide the name and version of the control panel):
No.
The version of my client is (e.g. output of certbot --version
or certbot-auto --version
if you're using Certbot):
I should be running the latest certbot dockerhub image.