Use simp_le to update certificates and link them to the /etc/nginx/certs directory
This commit is contained in:
parent
b89af421f6
commit
cca8c2d5cd
1 changed files with 18 additions and 10 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue