diff --git a/app/functions.lib b/app/functions.lib index 1e0f51e..8364313 100644 --- a/app/functions.lib +++ b/app/functions.lib @@ -3,10 +3,10 @@ declare -r START_HEADER='## Start of configuration add by letsencrypt container' declare -r END_HEADER='## End of configuration add by letsencrypt container' add_location_configuration() { - local domain="$1" - [[ -z "$domain" || ! -f "${VHOST_DIR}/${domain}" ]] && domain=default - [[ -f "${VHOST_DIR}/${domain}" && \ - -n $(sed -n "/$START_HEADER/,/$END_HEADER/p" "${VHOST_DIR}/${domain}") ]] && return 0 + local domain="$1" + [[ -z "$domain" || ! -f "${VHOST_DIR}/${domain}" ]] && domain=default + [[ -f "${VHOST_DIR}/${domain}" && \ + -n $(sed -n "/$START_HEADER/,/$END_HEADER/p" "${VHOST_DIR}/${domain}") ]] && return 0 echo "$START_HEADER" > "${VHOST_DIR}/${domain}".new cat /app/nginx_location.conf >> "${VHOST_DIR}/${domain}".new echo "$END_HEADER" >> "${VHOST_DIR}/${domain}".new @@ -21,3 +21,10 @@ remove_all_location_configurations() { sed -i "/$START_HEADER/,/$END_HEADER/d" "$file" done } + +reload_nginx() { + if [[ -n "$NGINX_PROXY_CID" ]]; then + /usr/bin/docker exec -t $NGINX_PROXY_CID \ + sh -c '/usr/local/bin/docker-gen -only-exposed /app/nginx.tmpl /etc/nginx/conf.d/default.conf;nginx -s reload' + fi +} diff --git a/app/letsencrypt_service b/app/letsencrypt_service index d7657dd..b47f5cb 100755 --- a/app/letsencrypt_service +++ b/app/letsencrypt_service @@ -7,21 +7,16 @@ acme_ca_uri="${ACME_CA_URI:-https://acme-v01.api.letsencrypt.org/directory}" source /app/functions.lib -reload_nginx() { - /usr/bin/docker exec -t $NGINX_PROXY_CID \ - sh -c '/usr/local/bin/docker-gen -only-exposed /app/nginx.tmpl /etc/nginx/conf.d/default.conf;nginx -s reload' -} - update_certs() { [[ ! -f "$DIR"/letsencrypt_service_data ]] && return # Load relevant container settings - unset LETSENCRYPT_CONTAINERS + unset LETSENCRYPT_CONTAINERS source "$DIR"/letsencrypt_service_data reload_nginx='false' for cid in "${LETSENCRYPT_CONTAINERS[@]}"; do - # Derive host and email variable names + # Derive host and email variable names host_varname="LETSENCRYPT_${cid}_HOST" # Array variable indirection hack: http://stackoverflow.com/a/25880676/350221 hosts_array=$host_varname[@]