Use simp_le to update certificates and link them to the /etc/nginx/certs directory

This commit is contained in:
David Parrish 2015-11-21 17:52:31 -05:00
parent b89af421f6
commit cca8c2d5cd

View file

@ -5,31 +5,39 @@ echo 'Waiting'
sleep 10
# Wait some amount of time
seconds_to_wait=10;
seconds_to_wait=3600;
while true; do
# Load relevant conatiner settings
source $DIR/letsencrypt_service_data
for lec in "${LETSENCRYPT_CONTAINERS[@]}"; do
# Derive host and email variable names
host_varname="LETSENCRYPT_""$lec""_HOST"
# Array variable indirection hack: http://stackoverflow.com/a/25880676/350221
hosts_array=$host_varname[@]; echo ${!hosts_array}
email_varname="LETSENCRYPT_""$lec""_EMAIL"; echo ${!email_varname}
# Wait until the threshold is reached for renewing certificate
# cat /etc/nginx/certs/ftl3.local.crt | openssl x509 -noout -dates
# Or if the certificate doesn't exist
hosts_array=$host_varname[@]
email_varname="LETSENCRYPT_""$lec""_EMAIL"
domain_params=""
for domain in "${!hosts_array}"; do
domain_params+="-d $domain "
done
# Use the first domain to create the directory
primary_domain=${!host_varname}
mkdir -p /etc/nginx/certs/$primary_domain
cd /etc/nginx/certs/$primary_domain
/opt/simp_le/venv/bin/simp_le $domain_params -f fullchain.pem -f key.pem --email ${!email_varname} --default_root /usr/share/nginx/html/
simp_le_return=$?
cd /app
# Copy certificates into /etc/nginx/certs
#cp /etc/letsencrypt/live/
# Symlink to created certificate and key.
for domain in "${!hosts_array}"; do
ln -s /etc/nginx/certs/$primary_domain/fullchain.pem /etc/nginx/certs/$domain".crt"
ln -s /etc/nginx/certs/$primary_domain/key.pem /etc/nginx/certs/$domain".key"
done
# TODO: Regenerate nginx config if simp_le created a certificate and key
#if [ "$simp_le_return" -eq 0 ]; then nginx -s reload; fi
unset $host_varname; unset $email_varname; unset $hosts_array
done