Skip to content

Instantly share code, notes, and snippets.

@mpolinowski
Created March 5, 2019 14:17
Show Gist options
  • Save mpolinowski/50b5d82f8b15842b3e2aa1dc4fa59483 to your computer and use it in GitHub Desktop.
Save mpolinowski/50b5d82f8b15842b3e2aa1dc4fa59483 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