diff --git a/root/app/auto-proxy.sh b/root/app/auto-proxy.sh index 2e2f1754..80e841fd 100755 --- a/root/app/auto-proxy.sh +++ b/root/app/auto-proxy.sh @@ -1,6 +1,7 @@ #!/usr/bin/with-contenv bash AUTO_GEN="" +REMOVED_CONTAINERS="" # figure out which containers to generate confs for or which confs to remove if [ ! -f /auto-proxy/enabled_containers_"$DOCKER_HOST_NAME" ]; then docker ps --filter "label=swag=enable" --format "{{.Names}}" > /auto-proxy/enabled_containers_"$DOCKER_HOST_NAME" @@ -187,11 +188,26 @@ DUDE fi done -if ([ -n "${AUTO_GEN}" ] || [ "${REMOVED_CONTAINERS}" == "true" ]) && ps aux | grep [n]ginx: > /dev/null; then - if /usr/sbin/nginx -c /config/nginx/nginx.conf -t; then - echo "**** Changes to nginx config are valid, reloading nginx ****" - /usr/sbin/nginx -c /config/nginx/nginx.conf -s reload - else - echo "**** Changes to nginx config are not valid, skipping nginx reload. Please double check the config including the auto-proxy confs. ****" - fi +if [ "${DIAG_EXIT}" == "true" ]; then + if ([ -n "${AUTO_GEN}" ] || [ "${REMOVED_CONTAINERS}" == "true" ]) && ps aux | grep [n]ginx: > /dev/null; then + if /usr/sbin/nginx -c /config/nginx/nginx.conf -t; then + echo "**** $DOCKER_HOST_NAME - Changes to nginx config are valid ****" + return 200; + else + echo "**** $DOCKER_HOST_NAME - Changes to nginx config are not valid. Please double check the config including the auto-proxy confs. ****" + return 201; + fi + else + return 0; + fi +else + if ([ -n "${AUTO_GEN}" ] || [ "${REMOVED_CONTAINERS}" == "true" ]) && ps aux | grep [n]ginx: > /dev/null; then + if /usr/sbin/nginx -c /config/nginx/nginx.conf -t; then + echo "**** $DOCKER_HOST_NAME - Changes to nginx config are valid, reloading nginx ****" + /usr/sbin/nginx -c /config/nginx/nginx.conf -s reload + else + echo "**** $DOCKER_HOST_NAME - Changes to nginx config are not valid, skipping nginx reload. Please double check the config including the auto-proxy confs. ****" + fi + fi fi + diff --git a/root/app/docker-wrap.sh b/root/app/docker-wrap.sh index 57c1b4e5..6b2d59a1 100755 --- a/root/app/docker-wrap.sh +++ b/root/app/docker-wrap.sh @@ -1,5 +1,9 @@ #!/usr/bin/with-contenv bash +RELOAD_NGINX="false" +NGINX_VALID="true" +DIAG_EXIT="true" + HOST_TLD_ORIG=${AUTO_PROXY_HOST_TLD:=*} if [[ -v FIRST_RUN ]];then echo '**** Auto Proxy - first-run ****' @@ -33,6 +37,12 @@ if [[ -v DOCKER_HOST ]];then echo "**** Auto Proxy - Generating proxies for => Host: ${DOCKER_HOST} | Name: ${DOCKER_HOST_NAME:-N/A} | Default Upstream IP: ${UPSTREAM_HOST} | Host TLD: ${AUTO_PROXY_HOST_TLD} ****" fi . /app/auto-proxy.sh + RES=$? + if [ $RES == 201 ]; then + NGINX_VALID="false" + elif [ $RES == 200 ]; then + RELOAD_NGINX="true" + fi let INDEX=${INDEX}+1 done @@ -46,7 +56,19 @@ if [ -S /var/run/docker.sock ]; then unset DOCKER_HOST unset UPSTREAM_HOST . /app/auto-proxy.sh + RES=$? + if [ $RES == 201 ]; then + NGINX_VALID="false" + elif [ $RES == 200 ]; then + RELOAD_NGINX="true" + fi fi + +if [ "${NGINX_VALID}" == "true" ] && [ "${RELOAD_NGINX}" == "true" ]; then + echo "**** All changes to nginx config are valid, reloading nginx ****" + /usr/sbin/nginx -c /config/nginx/nginx.conf -s reload +fi + if [[ -v FIRST_RUN ]];then echo '**** Auto Proxy - first-run finished ****' fi \ No newline at end of file