I never knew this (renewing certbot action)

I imagine most people already know this, but posting in case it does help someone. I have a little nginx install that I run on an SER beelink, that mirrors the one I always spam here, srobb.net. Anyway, it uses letsencrypt and runs nginx. I had never figured out how to get it to work right--I always had to stop nginx, and renew the cert. Today, while bored, decided to web search it a bit. Anyway, assuming one installs the py312-certbot-nginx plugin, one can do it with a cron job.
(Most of you know this, but the problem would be that certbot couldn't renew because nginx was using port 80. Therefore, it had to be stopped for the renewal.)

Code:
0 5 * * sun  /usr/local/bin/certbot renew --nginx >> /var/log/certbot >> /var/log/letsencrypt/letsencrypt.log
For any real beginners unfamiliar with cron, the time and day are arbitrary. The trick is the renew and the --nginx part.

Anyway, though I feel foolish not having learned this earlier, better late than never. It was something I kept planning to investigate and always forgetting, then I'd see my cert expired and stop nginx, renew the cert and start nginx again.

EDIT: See post #7, I've changed to using periodic to do this.
 
Last edited:
I kind-of like the renewal decoupled; I might use the certs for something else besides webserver (like prosody or Mumble) and it contains any failures to acme vs wondering about nginx (makes it easy to swap another webserver too or not need one/maintain an easier just-cert method cross-env)
 
I imagine most people already know this, but posting in case it does help someone. I have a little nginx install that I run on an SER beelink, that mirrors the one I always spam here, srobb.net. Anyway, it uses letsencrypt and runs nginx. I had never figured out how to get it to work right--I always had to stop nginx, and renew the cert. Today, while bored, decided to web search it a bit. Anyway, assuming one installs the py312-certbot-nginx plugin, one can do it with a cron job.
(Most of you know this, but the problem would be that certbot couldn't renew because nginx was using port 80. Therefore, it had to be stopped for the renewal.)

Code:
0 5 * * sun  /usr/local/bin/certbot renew --nginx >> /var/log/certbot >> /var/log/letsencrypt/letsencrypt.log
For any real beginners unfamiliar with cron, the time and day are arbitrary. The trick is the renew and the --nginx part.

Anyway, though I feel foolish not having learned this earlier, better late than never. It was something I kept planning to investigate and always forgetting, then I'd see my cert expired and stop nginx, renew the cert and start nginx again.
Hellow and thanks, but small thing in cron line, there are two >> redirects in a row, so only the last one gets the output and /var/log/certbot will just stay empty. Also, if you'd rather not keep your own cron entry, the py-certbot port ships a periodic script, so weekly_certbot_enable="YES" in /etc/periodic.conf does a weekly renew too (there's a weekly_certbot_deploy_hook if you need to reload nginx afterwards).
 
www/caddy does this for you.
www/angie*[1] and www/nginx*[2] as well:

[1] https://en.angie.software/angie/docs/configuration/modules/http/http_acme/
[2] https://nginx.org/en/docs/http/ngx_http_acme_module.html


Another ACME client that doesn't require python and its craptons of dependencies would be security/acme.sh which I've been using for many years for anything "not angie". It even tells you about its example cron configuration at installation:
Code:
$ pkg info -D acme.sh
[...]
* Please review /usr/local/share/examples/acme.sh/acme.sh-cron.d - instructions are
  contained in that file.
[...]
This file contains some sample cron entries and extensive documentation.
 
After reading JewelStar 's post I investigated why periodic gave me the same error of port 80 being busy if I tried periodic. Turned out that I had set it as standalone. Redoing the cert with certonly --nginx enabled periodic to run correctly. So, I now have
/etc/periodic.conf
weekly_certbot_enable="YES" weekly_certbot_deploy_hook="service nginx reload"

and testing with
Code:
certbot renew --dry-run
shows that it was successful.

sko I used acme before, on Linux I think (not sure) but for some reason I changed back to certbot, I don't remember why.
 
There is a similar plugin for apache, currently py312-certbot-apache. /etc/periodic.conf setup
Code:
weekly_certbot_enable="YES"
weekly_certbot_post_hook="service apache24 onereload"
no need for a separate cron job.
 
Back
Top