root crontab
# m h dom mon dow command
# at 2:06AM run certbot renew
6 2 * * * /usr/local/bin/certbot-renew
/usr/local/bin/certbot-renew
certbot renew sets $RENEWED_DOMAINS to a space separated list cert renewed domains. You can use it to trigger a nginx reload and commit the updated certs to version control
#!/bin/bash
PATH=/usr/bin:/bin:/sbin
/usr/bin/certbot renew --deploy-hook /usr/local/bin/certbot-deploy-hook
/usr/local/bin/certbot-deploy-hook
#!/bin/bash
GIT=/usr/bin/git
SYSTEM_CTL=/usr/bin/systemctl
if [ -n "$RENEWED_DOMAINS" ]; then
echo "Renewed domains: $RENEWED_DOMAINS"
echo "Reloading nginx because certs have been renewed"
$SYSTEM_CTL reload nginx
# commit new certs to version control
cd /etc && \
$GIT add -A && \
$GIT diff --cached --quiet || \
$GIT commit -m "Certbot deploy hook commit: /etc Letscencrypt changes ($(date '+%Y-%m-%d %H:%M:%S'))"
fi

0 Comments