Skip to content

Instantly share code, notes, and snippets.

@mauron85
Last active March 9, 2021 03:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mauron85/0912b899d473d58b9c37 to your computer and use it in GitHub Desktop.
Save mauron85/0912b899d473d58b9c37 to your computer and use it in GitHub Desktop.
Auto refresh LetsEncrypt cert for NGINX with letsencrypt-auto
#!/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
#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
#!/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