Skip to content

Instantly share code, notes, and snippets.

@dominhhai
Forked from mpolinowski/certbot-systemd-nginx.md
Created January 11, 2020 09:22
Show Gist options
  • Save dominhhai/5a4b9fe25f116332aae2fa73c2d699df to your computer and use it in GitHub Desktop.
Save dominhhai/5a4b9fe25f116332aae2fa73c2d699df to your computer and use it in GitHub Desktop.
NGINX Certbot certificate renewal with SystemD (Let's Encrypt)

Create a service unit file

$ nano /etc/systemd/system/certbot-renewal.service
[Unit]
Description=Certbot Renewal

[Service]
ExecStart=/usr/bin/certbot renew --pre-hook "service nginx stop" --post-hook "service nginx start"

Create a timer unit file

$ nano /etc/systemd/system/certbot-renewal.timer
[Unit]
Description=Timer for Certbot Renewal

[Timer]
OnBootSec=300
OnUnitActiveSec=1w

[Install]
WantedBy=multi-user.target

Start & Enable the Service

$ sudo systemctl start certbot-renewal.timer
$ sudo systemctl enable certbot-renewal.timer

Check Status

$ systemctl status certbot-renewal.timer
$ journalctl -u certbot-renewal.service
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment