Last active
March 9, 2021 03:20
-
-
Save mauron85/0912b899d473d58b9c37 to your computer and use it in GitHub Desktop.
Auto refresh LetsEncrypt cert for NGINX with letsencrypt-auto
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
echo "Running as user $USER" | |
DIR=/home/letsencrypt/letsencrypt | |
DOMAIN=mydomain.com | |
$DIR/letsencrypt-auto -a webroot --webroot-path /home/letsencrypt/webroot/ \ | |
--config-dir /home/letsencrypt/etc \ | |
--logs-dir /home/letsencrypt/log \ | |
--work-dir /home/letsencrypt/lib \ | |
--agree-dev-preview \ | |
--renew-by-default \ | |
--server https://acme-v01.api.letsencrypt.org/directory \ | |
-d "www.$DOMAIN" -d "$DOMAIN" certonly |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Copy this file into /etc/cron.d | |
SHELL=/bin/sh | |
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin | |
# m h dom mon dow user command | |
@monthly /home/letsencrypt/letsencrypt-nginx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
DIR=/home/letsencrypt | |
SCRIPT=letsencrypt-cert | |
USERNAME=letsencrypt | |
pushd $DIR | |
if [[ $USER != $USERNAME ]]; then | |
sudo -H -u $USERNAME ./$SCRIPT | |
else | |
./$SCRIPT | |
fi | |
popd | |
if [ $? -eq 0 ]; then | |
service nginx reload | |
echo OK | |
else | |
echo FAIL | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment