Created
April 7, 2016 23:00
-
-
Save lanrat/1cce4e66fe578aec26bc59fde9dfafa9 to your computer and use it in GitHub Desktop.
Letsencrypt renew scripts for docker
This file contains hidden or 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
#! /usr/bin/env bash | |
CERT_DIR=/etc/letsencrypt/live/ | |
for domain in $(ls $CERT_DIR) | |
do | |
cert_path="$CERT_DIR/$domain/cert.pem" | |
domains=$(openssl x509 -in $CERT_DIR/$domain/cert.pem -text | sed -nr '/^ {12}X509v3 Subject Alternative Name/{n;s/^ *//p}' | sed -e 's/DNS://g' | sed -e 's/,//g') | |
echo "$domains" | |
done |
This file contains hidden or 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
#! /usr/bin/env bash | |
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" | |
CERT_DIR=/etc/letsencrypt/live/ | |
CHECK_SECS=2592000 # 30 days | |
TMP_DIR=/tmp/letsencrypt | |
echo "Updating letsencrypt" | |
docker pull quay.io/letsencrypt/letsencrypt:latest | |
while read line; do | |
domains=($line) | |
primary=${domains[0]} | |
echo "Checking $primary" | |
cert_path="$CERT_DIR/$primary/cert.pem" | |
if ! openssl x509 -checkend $CHECK_SECS -noout -in $cert_path | |
then | |
echo "$line needs renewing" | |
docker_domains=$(echo $line | sed -e 's/ / -d /g' | sed -e 's/^/-d /g') | |
docker run -i --rm --name letsencrypt -v /etc/letsencrypt:/etc/letsencrypt -v /var/lib/letsencrypt:/var/lib/letsencrypt -v $TMP_DIR:/www quay.io/letsencrypt/letsencrypt:latest certonly --agree-to --text --renew-by-default --email EMAILv --webroot -w /www/ $docker_domains | |
sleep 5 | |
fi | |
done < ${DIR}/domains.txt | |
echo "Reloading nginx" | |
service nginx reload | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment