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
|
sleep 10
|
||||||
|
|
||||||
# Wait some amount of time
|
# Wait some amount of time
|
||||||
seconds_to_wait=10;
|
seconds_to_wait=3600;
|
||||||
while true; do
|
while true; do
|
||||||
# Load relevant conatiner settings
|
# Load relevant conatiner settings
|
||||||
source $DIR/letsencrypt_service_data
|
source $DIR/letsencrypt_service_data
|
||||||
|
|
||||||
for lec in "${LETSENCRYPT_CONTAINERS[@]}"; do
|
for lec in "${LETSENCRYPT_CONTAINERS[@]}"; do
|
||||||
|
# Derive host and email variable names
|
||||||
host_varname="LETSENCRYPT_""$lec""_HOST"
|
host_varname="LETSENCRYPT_""$lec""_HOST"
|
||||||
# Array variable indirection hack: http://stackoverflow.com/a/25880676/350221
|
# Array variable indirection hack: http://stackoverflow.com/a/25880676/350221
|
||||||
hosts_array=$host_varname[@]; echo ${!hosts_array}
|
hosts_array=$host_varname[@]
|
||||||
|
email_varname="LETSENCRYPT_""$lec""_EMAIL"
|
||||||
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
|
|
||||||
|
|
||||||
domain_params=""
|
domain_params=""
|
||||||
for domain in "${!hosts_array}"; do
|
for domain in "${!hosts_array}"; do
|
||||||
domain_params+="-d $domain "
|
domain_params+="-d $domain "
|
||||||
done
|
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/
|
/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
|
# Symlink to created certificate and key.
|
||||||
#cp /etc/letsencrypt/live/
|
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
|
unset $host_varname; unset $email_varname; unset $hosts_array
|
||||||
done
|
done
|
||||||
|
|
Loading…
Reference in a new issue