root crontab
6 3,15 * * * /usr/local/bin/certbot-renew
/usr/local/bin/certbot-renew
certbot renew sets $RENEWED_DOMAINS to a space separated list of domains that have had a cert renewed so you can use it to trigger a nginx reload and commit the certs to version control
#!/bin/bash
# unset PYTHON_INSTALL_LAYOUT
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
echo "Running certbot-deploy-hooks"
echo "Renewed domains: $RENEWED_DOMAINS"
if [ -n "$RENEWED_DOMAINS" ]; then
echo "Reloading nginx because certs have been renewed"
$SYSTEM_CTL reload nginx
# commit new certs to version control
cd /etc && \
$GITadd -A && \
$GIT diff --cached --quiet || \
$GIT commit -m "Auto-commit: /etc changes ($(date '+\%Y-\%m-\%d \%H:\%M:\%S'))"
fi

0 Comments